/* cheking no is armstrong or not */
#include<stdio.h>
#include<conio.h>
void main()
{
int no,sum=0,i,temp1,temp2;
clrscr();
printf("enter 3 digit positive no : ");
scanf("%d",&no);
temp1=no;
temp2=no;
while(temp2>0)
{
temp1=temp2%10;
sum=sum+(temp1*temp1*temp1);
temp2=temp2/10;
}
if(no==sum)
printf("\n %d is Armstrong Number",no);
else
printf("\n %d is not Armstrong Number",no);
getch();
}
Output :
#include<stdio.h>
#include<conio.h>
void main()
{
int no,sum=0,i,temp1,temp2;
clrscr();
printf("enter 3 digit positive no : ");
scanf("%d",&no);
temp1=no;
temp2=no;
while(temp2>0)
{
temp1=temp2%10;
sum=sum+(temp1*temp1*temp1);
temp2=temp2/10;
}
if(no==sum)
printf("\n %d is Armstrong Number",no);
else
printf("\n %d is not Armstrong Number",no);
getch();
}
Output :


No comments:
Post a Comment