In this tutorial learn how you can write a c program to display whether the entered number is an Armstrong number or not.
An Armstrong number is one whose sum of digits raised to the power three equals the number itself. 371, for example, is an Armstrong number because 3**3 + 7**3 + 1**3 = 371.
We are using for loop and if statement for this tutorial.
C programming is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, etc.
Write a Program to Calculate Factorial of a Number
Here is the code to display whether the entered number is Armstrong number or not in C programming.
#include <stdio.h> //WAP to display whether the entered number is Armstrong number or not. int main(){ int num,rem,sum=0,z; printf("Enter any number of your choices:"); scanf("%d",&num); z=num; while (num!=0) { rem=num%10; sum=sum+(rem*rem*rem); num=num/10; } if (z==sum) { printf("The entered number %d is Armstrong number.",z); } else printf("The entered number %d isnot Armstrong number.",z); return 0; }
Test Live At Jdoodle
Conclusion
This is how you can display whether the entered number is Armstrong number or not in c programming. Comment below if you like our tutorial.