udf
Question:
Write a function Armstrong that returns 1 if its argument is an Armstrong number and returns zero otherwise.
💡 Solutions (1)
Super Admin
AdminFeb 03, 2026 at 11:35
upvotes
#include <stdio.h> #include <math.h> int Armstrong(int num) { int original = num, remainder, digits = 0; int sum = 0, temp = num; // Count number of digits while (temp != 0) { digits++; temp = temp / 10; } // Calculate Armstrong sum temp = num; while (temp != 0) { remainder = temp % 10; sum = sum + pow(remainder, digits); temp = temp / 10; } // Check Armstrong if (sum == original) return 1; else return 0; } int main() { int n; printf("Enter a number: "); scanf("%d", &n); if (Armstrong(n)) printf("Armstrong Number\n"); else printf("Not an Armstrong Number\n"); return 0; }
Want to add your solution? Login to contribute!
💬 Comments (0)
Login to post comments
No comments yet
Be the first to comment!