Powered By Blogger

Feb 11, 2025

20. Check Armstrong Number for N Digits

 #include <stdio.h>

#include <math.h>

int main() {

    int num, temp, remainder, n = 0, sum = 0;

    printf("Enter a number: ");

    scanf("%d", &num);

    temp = num;

    while (temp != 0) {

        temp /= 10;

        n++;

    }

    temp = num;

    while (temp != 0) {

        remainder = temp % 10;

        sum += pow(remainder, n);

        temp /= 10;

    }

    if (sum == num)

        printf("Armstrong Number\n");

    else

        printf("Not an Armstrong Number\n");

    return 0;

}


No comments:

Post a Comment

Featured Post

Data Analysis

    What is data analysis and its significance?   Data analysis is the process of collecting, transforming, and organizing data to dr...

Popular Posts