armstrongNumbers.c

to check whether a number is a armstrong number or not
 avatar
unknown
c_cpp
6 months ago
719 B
3
Indexable
#include <stdio.h>
int main()
{
    int num, result, rem, qt, count, cnt, mul;
    count = result = 0;
    mul = 1;
    printf("Enter a number: ");
    scanf("%d", &num);

    qt = num;;

    while (qt != 0)
    {
        qt = qt / 10;
        count++;
    }

    cnt = count;
    qt = num;

    while (qt != 0)
    {
        rem = qt % 10;

        while (cnt != 0)
        {
            mul = mul * rem;
            cnt--;
        }

        result = result + mul;
        cnt = count;
        qt = qt / 10;
        mul = 1;
    }

    if(result == num)
    printf("%d is a ARMSTRONG number", num);
    else
    printf("%d is not a ARMSTRONG number", num);

    return 0;

}
Editor is loading...