udf

⚡ Functions C Medium
✅ Solved
Asked by Jariwala Jil Feb 03, 2026 at 11:34 Subject: Programming Skills

Question:

Write a function Armstrong that returns 1 if its argument is an Armstrong number and returns zero otherwise.

💬 0 Comments 💡 1 Solution(s)

💡 Solutions (1)

✅ ACCEPTED SOLUTION

Super Admin

Admin

Feb 03, 2026 at 11:35

👍 0

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; }

👍 Login to Vote

Want to add your solution? Login to contribute!

💬 Comments (0)

Login to post comments

No comments yet

Be the first to comment!