Write a Program in C to calculate Armstrong number using pointer.

#include<stdio.h>
#include<conio.h>
void main()
{
int arm=0,no,rem,*p,*pr,a;
clrscr();
printf("please enter the no. : ");
scanf("%d",&no);
a=no;
p=&no;
pr=&arm;
while(*p>0)
{
rem=(*p)%10;
*pr=(*pr)+(rem*rem*rem);
*p=(*p)/10;
}
if(a== *pr)
   printf("The number is armstrong");
else
   printf("The number is not armstrong");
getch();
}

No comments:

Post a Comment