Wednesday 9 February 2022

C Program to check whether a given number is Armstrong or Not

FIND IS GIVEN NUMBER ARMSTRONG OR NOT

Code :

#include<stdio.h>

int main()
{
    int num, sum=0, temp=0, res;
   
    printf("Enter a 3 digit number : ");
    scanf("%d", &num);


    temp = num;
   
    while(temp != 0)
    {
        res = temp % 10;
        sum += (res*res*res);
        temp = temp/10;
    }
   
   
    if(num == sum)
    {
        printf("\n\t%d is an Armstrong number",                               num);
    }


    else
    {
        printf("\n\t%d is Not  Armstrong number",                            num);
    }


    return 0;
}

Come again Learn again !

< icodebuzz />



No comments:

Post a Comment