Breaking News

Category Archives: Uncategorized

C Program to Display Characters from A to Z Using Loop

Example #1: Program to Display English Alphabets #include <stdio.h> int main() { char c; for(c = 'A'; c <= 'Z'; ++c) printf("%c ", c); return 0; } Output A B C D E F G H I J K L M N O P Q R S T U V W X Y Z In this program, the for loop ... Read More »

C Program to Count Number of Digits in an Integer

Example #1: Program to Count Number of Digits in an Integer #include <stdio.h> int main() { long long n; int count = 0; printf("Enter an integer: "); scanf("%lld", &n); while(n != 0) { // n = n/10 n /= 10; ++count; } printf("Number of digits: %d", count); } Output Enter an integer: 3452 Number of digits: 4 Read More »

C Program to Reverse a Number

#include <stdio.h> int main() { int n, reversedNumber = 0, remainder; printf("Enter an integer: "); scanf("%d", &n); while(n != 0) { remainder = n%10; reversedNumber = reversedNumber*10 + remainder; n /= 10; } printf("Reversed Number = %d", reversedNumber); return 0; } Output Enter an integer: 2345 Reversed Number = 5432 Read More »

C Program to Calculate the Power of a Number

Example #1: Power of a Number Using while Loop #include <stdio.h> int main() { int base, exponent; long long result = 1; printf("Enter a base number: "); scanf("%d", &base); printf("Enter an exponent: "); scanf("%d", &exponent); while (exponent != 0) { result *= base; --exponent; } printf("Answer = %lld", result); return 0; } Output Enter a base number: 3 Enter an ... Read More »

C Program to Find Factorial of a Number Using Recursion

The factorial of a positive number n is given by: factorial of n (n!) = 1*2*3*4....n #include <stdio.h> long int multiplyNumbers(int n); int main() { int n; printf("Enter a positive integer: "); scanf("%d", &n); printf("Factorial of %d = %ld", n, multiplyNumbers(n)); return 0; } long int multiplyNumbers(int n) { if (n >= 1) return n*multiplyNumbers(n-1); else return 1; } Output ... Read More »

C Program to Find Factorial of a Number

The factorial of a positive number n is given by: factorial of n (n!) = 1*2*3*4....n The factorial of a negative number doesn’t exist. And, the factorial of 0 is 1, 0! = 1 Example: Factorial of a Number #include <stdio.h> int main() { int n, i; unsigned long long factorial = 1; printf("Enter an integer: "); scanf("%d",&n); // show ... Read More »

C Program to Check Whether a Number is Palindrome or Not

#include <stdio.h> int main() { int n, reversedInteger = 0, remainder, originalInteger; printf("Enter an integer: "); scanf("%d", &n); originalInteger = n; // reversed integer is stored in variable while( n!=0 ) { remainder = n%10; reversedInteger = reversedInteger*10 + remainder; n /= 10; } // palindrome if orignalInteger and reversedInteger are equal if (originalInteger == reversedInteger) printf("%d is a palindrome.", ... Read More »

C Program to Print an Integer (Entered by the User)

Program to Print an Integer #include <stdio.h> int main() { int number; // printf() dislpays the formatted output printf("Enter an integer: "); // scanf() reads the formatted input and stores them scanf("%d", &number); // printf() displays the formatted output printf("You entered: %d", number); return 0; } Output Enter a integer: 25 You entered: 25 In this program, an integer variable┬ánumber ... Read More »

C Program to Add Two Integers

Program to Add Two Integers #include <stdio.h> int main() { int firstNumber, secondNumber, sumOfTwoNumbers; printf("Enter two integers: "); // Two integers entered by user is stored using scanf() function scanf("%d %d", &firstNumber, &secondNumber); // sum of two numbers in stored in variable sumOfTwoNumbers sumOfTwoNumbers = firstNumber + secondNumber; // Displays sum printf("%d + %d = %d", firstNumber, secondNumber, sumOfTwoNumbers); return ... Read More »

C Program to Find ASCII Value of a Character

Program to Print ASCII Value #include <stdio.h> int main() { char c; printf("Enter a character: "); // Reads character input from the user scanf("%c", &c); // %d displays the integer value of a character // %c displays the actual character printf("ASCII value of %c = %d", c, c); return 0; } Output Enter a character: G ASCII value of G ... Read More »

Scroll To Top