My Subject Blog

C Program Armstrong number

/* Write a program to print Armstrong number ( or Narcissistic no) between 0 to 999.( Armstrong no= addition of cube of every digit of a no, e.g. 153 is Armstrong due to 13+53+33=153)  */

#include <stdio.h>

int main(void) {
int n,r,no=0,sum=0;
while(no<1000)
{
n=no;
sum = 0;
while(n>0)
{
r = n % 10;
sum = sum + (r * r *r);
n = n / 10;
}
if(sum==no)
{
printf("%d ",no);
}
no++;
}

return 0;
}

Comments

Most Visited Post

C Program to Find Largest Odd Number from Array

Followers