Write a C program to check whether a number is Armstrong or Not!!!
byNEED WORK PRODUCE WORK-
1
ARMSTRONG NUMBER: The number which is equal to the sum of cubes of each of its digits.
LOGIC BUILDING:
Take input from user.
Apply an algorithm which separates the digit of number and and add cube of each.
Compare it with the original one.
If it is same as original print its Armstrong else its not Armstrong.
CODE:
#include<stdio.h> int main(){
int num,digit,sum=0,original; //intializing variables.
printf("Enter the Number: "); scanf("%d",&num);//taking number from user which he wants to check;
original=num; //preserving original number for comparation
while (num!=0) { digit=num%10; // %10 will give us last digit of a number sum=sum+(digit*digit*digit); //addition of num will be stored with this algorithm
num/=10; // it means num=num/10;
} if (original==sum) //comparation going on printf("\nThe number %d is a Armstrong",sum); else printf("\nThe number %d is not a Armstrong",original); getchar(); return 0; }
Like Always You Have Done Your Best Keep The Work Up.
ReplyDelete