C Program to check whether the given number is Armstrong or not (use user defined function).

#include
#include
int main()
{
int n, n1, rem, num=0;
clrscr();
printf("Enter a positive  integer : ");
scanf("%d", &n);
n1=n;
while(n1!=0)
{
rem=n1%10;
num+=rem*rem*rem;
n1/=10;
}
if(num==n)
printf("\n%d is an Armstrong number.",n);
else
printf("\n%d is not an Armstrong number.",n);
getch();
}



Alogithm
step1:start
step2:intialize num<-0 p="">step3:Read n
step4:n1=n
step5:check whether n1!=0,then go to step 6
      else go to step 10
step6:rem=n1%10
step7:num=num+rem*rem*rem
step8:n1=n1/10
step9:go to step 5
step10:check whether num =n,then go to step 11
       else go to step 12
step11:print armstrong number
step12:print not armstrong number
step13:stop

1 comment: