This Program is for Verifying or Identifying A Number is an Armstrong Number or Not,
This program is applicable for identifying any digits of a number is Armstrong number or not.
#include <stdio.h>
main()
{
int number,temp,i=0,j=0,result=0,power,dig,remain;
printf("\nEnter Any Number:\n");
scanf("%d",&number);
temp=number;
while(temp!=0) //for(temp=number;temp!=0;temp/=10) {i++}
{
temp/=10; //temp=temp/10;
i++;
}
printf("\nYOU HAVE ENTERED The Number %d Which is A %d DIGIT Number",number,i);
for(temp=number;temp!=0;temp/=10)
{
printf("\n\nAfter %d Loop Temp Value is \t %d\n\n",j,temp);
power=1;
remain=temp%10;
printf("\n Remain is %d \t When Temp Value is = %d",remain,temp);
dig=i;
for(i=0;i<dig;i++)
{
power*=remain; //power = power*remain;
}
printf("\n Power Value = %d \t When Temp Value is = %d",power,temp);
result+=power; //result = result+power;
printf("\n Result Value = %d \t When \t Temp Value is = %d",result,temp);
j++;
}
if(result==number)
{
printf("\n\nUltimate Result\n\nYou Have Entered %d Number and It is a Armstrong Number as \nResult = \t %d and Number = \t %d is Same",number,result,number);
}
else
{
printf("\n\nUltimate Result\n\nYou Have Entered %d Number and It is NOT a Armstrong Number as \nResult = \t %d and Number = \t %d is NOT Same",number,result,number);
}
}
RESULT WILL BE LIKE THAT >>
No comments:
Post a Comment