while Loop in C Programming
Get Certified in C Programming and Take Your Skills to the Next Level
Program 1
// Program for factorial of number
#include<stdio.h>
#include<conio.h>
int main()
{
system("cls");
int n,f=1,m;
printf("Enter a number");
scanf("%d",&n);
m=n;
while(n!=0)
{
f=f*n;
n--;
}
printf("Factorial of %d is %d ",m,f);
return 0;
}
Program 2
// Program for addition of individual digits
#include<stdio.h>
#include<conio.h>
int main()
{
system("cls");
int n,r,s=0;
printf("Enter a number");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("Addition is %d: ",s);
return 0;
}
Program 3
// Program for reverse of number
#include<stdio.h>
#include<conio.h>
int main()
{
system("cls");
int n,r,s=0,m;
printf("Enter a number");
scanf("%d",&n);
m=n;
while(n!=0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
printf("Reverse of %d is %d ",m,s);
return 0;
}
Program 4
// Program for palindrom number
#include<stdio.h>
#include<conio.h>
int main()
{
system("cls");
int n,r,s=0,m;
printf("Enter a number");
scanf("%d",&n);
m=n;
while(n!=0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(m==s)
printf("No is Palimdrom");
else
printf("No is not Palimdrom");
return 0;
}
Program 5
// Program for armstrong number
#include<stdio.h>
#include<conio.h>
int main()
{
system("cls");
int n,r,s=0,m;
printf("Enter a number");
scanf("%d",&n);
m=n;
while(n!=0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(m==s)
printf("No is Armstrong");
else
printf("No is not Armstrong");
return 0;
}
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

