Breaking News

Category Archives: C program

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 »

C Program to Check Whether a Character is Vowel or Consonant

The five alphabets A, E, I, O and U are called vowels. All other alphabets except these 5 vowel letters are called consonants. This program assumes that the user will always enter an alphabet character. Example #1: Program to Check Vowel or consonant #include <stdio.h> int main() { char c int isLowercaseVowel, isUppercaseVowel; printf("Enter an alphabet: "); scanf("%c",&c); // evaluates ... Read More »

C Program to Find the Largest Number Among Three Numbers

Example #1 #include <stdio.h> int main() { double n1, n2, n3; printf("Enter three numbers: "); scanf("%lf %lf %lf", &n1, &n2, &n3); if( n1>=n2 && n1>=n3 ) printf("%.2f is the largest number.", n1); if( n2>=n1 && n2>=n3 ) printf("%.2f is the largest number.", n2); if( n3>=n1 && n3>=n2 ) printf("%.2f is the largest number.", n3); return 0; } This program uses ... Read More »

C program to Find all Roots of a Quadratic equation

#include <stdio.h> #include <math.h> int main() { double a, b, c, determinant, root1,root2, realPart, imaginaryPart; printf("Enter coefficients a, b and c: "); scanf("%lf %lf %lf",&a, &b, &c); determinant = b*b-4*a*c; // condition for real and different roots if (determinant > 0) { // sqrt() function returns square root root1 = (-b+sqrt(determinant))/(2*a); root2 = (-b-sqrt(determinant))/(2*a); printf("root1 = %.2lf and root2 = ... Read More »

C Program to Check Whether a Number is Prime or Not

A prime number is a positive integer which is divisible only by 1 and itself. For example: 2, 3, 5, 7, 11, 13 Example: Program to Check Prime Number #include <stdio.h> int main() { int n, i, flag = 0; printf("Enter a positive integer: "); scanf("%d",&n); for(i=2; i<=n/2; ++i) { // condition for nonprime number if(n%i==0) { flag=1; break; } ... Read More »

C Programming Code To Create Pyramid and Pattern

Programs to print triangles using *, numbers and characters Example 1: Program to print half pyramid using * * * * * * * * * * * * * * * * Source Code #include <stdio.h> int main() { int i, j, rows; printf("Enter number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; ++i) { for(j=1; j<=i; ++j) { printf("* "); ... Read More »

Add digits of a number C PROGRAM

#include <stdio.h> int main() { int n, sum = 0, remainder; printf(“Enter an integer\n”); scanf(“%d”, &n); while (n != 0) { remainder = n % 10; sum = sum + remainder; n = n / 10; } printf(“Sum of digits of entered number = %d\n”, sum); return 0; }   OUTPUT Enter an integer 1659 Sum of digits of entered ... Read More »

Scroll To Top