Breaking News

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 »

C Program to Compute Quotient and Remainder

Program to Compute Quotient and Remainder #include <stdio.h> int main(){ int dividend, divisor, quotient, remainder; printf("Enter dividend: "); scanf("%d", &dividend); printf("Enter divisor: "); scanf("%d", &divisor); // Computes quotient quotient = dividend / divisor; // Computes remainder remainder = dividend % divisor; printf("Quotient = %d\n", quotient); printf("Remainder = %d", remainder); return 0; } Output Enter dividend: 25 Enter divisor: 4 Quotient ... Read More »

C Program to Find the Size of int, float, double and char

Example: Program to Find the Size of a variable #include <stdio.h> int main() { int integerType; float floatType; double doubleType; char charType; // Sizeof operator is used to evaluate the size of a variable printf("Size of int: %ld bytes\n",sizeof(integerType)); printf("Size of float: %ld bytes\n",sizeof(floatType)); printf("Size of double: %ld bytes\n",sizeof(doubleType)); printf("Size of char: %ld byte\n",sizeof(charType)); return 0; } Output Size of ... Read More »

C Program to Swap Two Numbers

Example 1: Program to Swap Numbers Using Temporary Variable #include <stdio.h> int main() { double firstNumber, secondNumber, temporaryVariable; printf("Enter first number: "); scanf("%lf", &firstNumber); printf("Enter second number: "); scanf("%lf",&secondNumber); // Value of firstNumber is assigned to temporaryVariable temporaryVariable = firstNumber; // Value of secondNumber is assigned to firstNumber firstNumber = secondNumber; // Value of temporaryVariable (which contains the initial value ... Read More »

C Program to Check Whether a Number is Even or Odd

Example #1: Program to Check Even or Odd #include <stdio.h> int main() { int number; printf("Enter an integer: "); scanf("%d", &number); // True if the number is perfectly divisible by 2 if(number % 2 == 0) printf("%d is even.", number); else printf("%d is odd.", number); return 0; } Output Enter an integer: -7 -7 is odd. In the program, integer ... Read More »

Scroll To Top