#include<stdio.h>
#include<conio.h>
void main()
{
int c,n,d,on,s=0;
clrscr();
printf("\nEnter Three Digit Number ");
scanf("%d",&n); //567
on=n;
while(n!=0)
{
d=n%10; //153%10 d=3 15%10 d=5 1%10 d=1
c=d*d*d; //3*3*3 c=27 //5*5*5 c=125 1*1*1 c=1
s=s+c; //0+27 s=27 27+125 s=152 152+1 s=153
n=n/10; //153/10 n=15 15/10 n=1 1/10 n=0
}
printf("\nSum of Cube of Digit = %d",s);
if(s==on)
{
printf("\nArmstrong");
}
else
{
printf("\nNot Armstrong");
}
getch();
}
#include<conio.h>
void main()
{
int c,n,d,on,s=0;
clrscr();
printf("\nEnter Three Digit Number ");
scanf("%d",&n); //567
on=n;
while(n!=0)
{
d=n%10; //153%10 d=3 15%10 d=5 1%10 d=1
c=d*d*d; //3*3*3 c=27 //5*5*5 c=125 1*1*1 c=1
s=s+c; //0+27 s=27 27+125 s=152 152+1 s=153
n=n/10; //153/10 n=15 15/10 n=1 1/10 n=0
}
printf("\nSum of Cube of Digit = %d",s);
if(s==on)
{
printf("\nArmstrong");
}
else
{
printf("\nNot Armstrong");
}
getch();
}
No comments:
Post a Comment