Monday, 31 December 2018

Find Armstrong Number[c programming examples with output]

C programming examples with output:

Find Armstrong 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(a>0)
{
          d=a%10;
          c=c+(d*d*d);
          a=a/10;
}
if(d==c)
          printf("%d is an Armstrong Number",b);
else
          printf("%d is not an Armstrong Number",b);
getch();
}

Output

Enter any number: 153
153 is an Armstrong Number
Enter any number 167
167 is not an Armstrong Number

Find Average Of Odd Numbers Below A Range[c programming examples with output]

C programming examples with output

Find Average Of Odd Numbers Below A Range
Program

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d;
float f;
clrscr();
printf("Enter the range: ");
scanf("%d",&b);
a=1;c=0;d=0;
while(a<=b)
{
            if(a%2!=0)
      {
d=d+a;
c++;
}
           a++;
}
f=d/c;
printf("\nThe average of odd numbers below %d: %f",b,f);
getch();
}


Output
Enter the range:20
The average of odd numbers below 20: 10.000000


Check others programming by click here:

Find perfect number or not[c programming examples with output]

C programming examples with output

Find perfect number or not
Program

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

Output
Enter any number: 6
6 is a Perfect number
Enter any number:33
33 is not a Perfect number


Check others programming by click here:

Even number upto a range[c programming examples with output]

C programming examples with output

Even number upto a range
Program

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
printf("Enter the range: ");
scanf("%d",&a);
b=1;
while(b<=a)
{
        if(b%2==0)
          printf("%d/t",b);
          b++;
}
getch();
}

Output
Enter the range:10