Write a C-program to print out all Armstrong numbers between 1 and 500.

 TASK-

Write a C-program to print out all Armstrong numbers between 1 and 500.  

/*Note: If sum of cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + 
( 3 * 3 * 3 )*/ 
For better understanding click here 👉👉 ARMSTRONG NUMBER

CODE:


#include<stdio.h>
int main(){

        int s=0,digit,original;
printf("\n\t Armstrong numbers from 1 to 500: ");

for (int i=1;i<=500;i++)
{
original=i;

     while (original!=0) // this loop is used to break the number in digits For better understanding click here 👉👉 ARMSTRONG NUMBER
{
digit=original%10;
s=s+(digit*digit*digit);
original/=10;
}

        if (s==i)
printf("\n\t%d",i);
s=0;
}
getchar();
return 0;
}

EXPECTED CODE:



NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

Post a Comment (0)
Previous Post Next Post