Breaking News

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 »

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 ... Read More »

Add ‘n’ numbers using array C PROGRAM

#include <stdio.h>   int main() {    int n, sum = 0, c, array[100];      printf("Enter the number of integers you want to add\n");    scanf("%d", &n);      printf("Enter %d integers\n",n);      for (c = 0; c < n; c++)    {       scanf("%d", &array[c]);       sum = sum + array[c];    }      printf("Sum = %d\n",sum);      return 0; } OUTPUT Enter the number of ... Read More »

Add ‘n’ numbers C PROGRAM

#include <stdio.h>   int main() {    int n, sum = 0, c, value;      printf("Enter the number of integers you want to add\n");    scanf("%d", &n);      printf("Enter %d integers\n",n);      for (c = 1; c <= n; c++)    {       scanf("%d",&value);       sum = sum + value;    }      printf("Sum of entered integers = %d\n",sum);      return 0; } OUTPUT Enter the ... Read More »

ASCII value of character C PROGRAM

#include <stdio.h> int main() {     char c;     printf("Enter a character: ");     scanf("%c",&c);     printf("ASCII value of %c = %d",c,c);     return 0; } OUTPUT Enter a character: A ASCII value of A = 65 Read More »

Scroll To Top