Home > Backend Development > C++ > body text

C program to check Armstrong number?

WBOY
Release: 2023-09-11 13:01:02
forward
1130 people have browsed it

C program to check Armstrong number?

If the sum of the cubes of the digits of a number is equal to the number itself, it is called Armstrong's number. This is a mathematical concept often used in programming to build the programmer's basic logic. The Chinese translation of

Input:370
Output:370 is an Armstrong Number
Copy after login

Explanation

is:

Explanation

370 = 3*3*3 + 7*7*7 + 0*0*0
= 27 + 343 + 0
= 370
Copy after login

Example

include <iostream>
using namespace std;
int main() {
   int n, num, rem, sum = 0;
   cin >> n;
   num = n;
   while(num != 0) {
      digit = num % 10;
      sum += digit * digit * digit;
      num /= 10;
   }
   if(sum == n)
      printf("%d is an Armstrong number.", n );
   else
      printf("%d is not an Armstrong number.",n);
   return 0;
}

Copy after login

The above is the detailed content of C program to check Armstrong number?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template