Armstrong number

Program:

#include<stdio.h>
int main()
{
int n,sum=0,rem,temp;
printf("Enter number: ");
scanf("%d",&n);
temp=n;
while(n>0)
{
rem=n%10; /*separate the digit*/
sum=sum+(rem*rem*rem); /*cube of digit and add to sum*/
n=n/10; /*new n after separation of digit*/
}
if(sum==temp)
{
printf("Armstrong number");
}
else
{
printf("Not a Armstrong number");
}
return 0;

}

Output:




No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...