Tuesday 1 January 2019

Factorial of a number[c programming examples with output]

C programming examples with output

Factorial of a number

Program
#include<stdio.h>
#include<conio.h>
main()
{
       int a,b,c;
       clrscr();
       printf("Enter any number: ");
       scanf("%d",&a);
       c=a;
       b=1;
       while(c>0)
       {
       b=b*c;
       c-;
       }
       printf("Factorial of %d is:  %d",a,b);
       getch();
}

Output

Enter any number:6
Factorial of 6 is:720


Find sum of digits of a number[c programming examples with output]

C programming examples with output

Find sum of digits of a number

Program

#include<stdio.h>
#include<conio.h>
main()
{
       int a,b;
       long n;
       clrscr();
       printf("Enter any numbr: ");
       scanf("%ld",&n);
       b=0;
       while(n>0)
       {
             a=n%10;
             b=b+a;
             n=n/10;
        }
        printf("The sum of digits is %d",b);
        getch();
}

Output

Enter any number: 45632
The sum of digits is 20

Find vowel or not[c programming examples with output]


C programming examples with output:

Find vowel or not

Program
#include<stdio.h>
#include<conio.h>
main()
{
       char ch;
       clrscr();.
       printf("Enter any charecter: ");
       scanf("%c",&ch);
       switch(ch)
       {
          case 'A':
                  printf("%c is a vowel",ch);
                  break;
          case 'E':
                  printf("%c is a vowel",ch);
                  break;
          case 'I':
                  printf("%c is a vowel",ch);
                  break;
          case 'O':
                  prinntf)'%c is a vowel",ch);
                  break;
          case 'U':
                  printf("%c is a vowel",ch);
                  break;
                  default:
                  printf("%c is not a vowel",ch);
                   }
                  getch();
}

Output

Enter any character: a
a is a vowel
Enter any character: x
x is not a vowel

Find Palindrome Number[c programming examples with output]

C programming examples with output

Palindrome Number


Program

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d;
clrscr();
printf("Enter any number: ");
scanf("%d",&a);
b=a;
c=0;
while(n>0)
{
        d=a%10;
        c=(c*10)+d;
        a=a/10;
}
if(b==c)
          printf("%d is Palindrome Number",b);
else
          printf("%d is not Palindrome Number",b);
getch();
}

Output

Enter any number:135
135 is not Palindrome Number
Enter any number:121
121 is Palindrome NUmber