 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check the number is Armstrong or not using C
Problem
How to check whether the given number is an Armstrong number or not using C Programming language?
Solution
Armstrong number is the number that is equal to the sum of cubes of its digits.
Syntax
pqrs………=pow(p,n)+pow(q,n)+pow(r,n)+……….
For example, 153,371,1634, etc., are Armstrong numbers.
153=1*1*1 + 5*5*5 + 3*3*3 =1+125+27 =153 (Armstrong number)
Program
#include<stdio.h> int main(){    int number,remainder,total=0,temp;    printf("enter the number=");    scanf("%d",&number);    temp=number;    while(number>0){       remainder=number%10;       total=total+(remainder*remainder*remainder);       number=number/10;    }    if(temp==total)       printf("This number is Armstrong number");    else       printf("This number is not Armstrong number");    return 0; } Output
enter the number=371 This number is Armstrong number Check: 371=3*3*3 +7*7*7 + 1*1*1 =27 + 343 +1 =371 enter the number=53 This number is not Armstrong number
Explanation
53 = 5*5*5 + 3*3*3 =125 +27 = 152 != 53
Advertisements
 