Users Online

· Guests Online: 146

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

35 C Program to Check whether a given Number is Armstrong

This C Program checks whether a given number is armstrong number. An Armstrong number is an n-digit base b number such that the sum of its (base b) digits raised to the power n is the number itself. Hence 153 because 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153.
Here is source code of the C Program to check whether a given number is armstrong number.
The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to Check whether a given Number is Armstrong
*/
#include <stdio.h>
#include

void main()
{
int number, sum = 0, rem = 0, cube = 0, temp;

printf ("enter a number");
scanf("%d", &number);
temp = number;
while (number != 0)
{
rem = number % 10;
cube = pow(rem, 3);
sum = sum + cube;
number = number / 10;
}
if (sum == temp)
printf ("The given no is armstrong no");
else
printf ("The given no is not a armstrong no");
}

Output:
$ cc pgm41.c -lm
$ a.out
enter a number370
The given no is armstrong no

$ a.out
enter a number1500
The given no is not a armstrong no

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.07 seconds
10,817,772 unique visits