Write a program to know whether the input number is an armstrong number.



Write a program to know whether the input number is an armstrong number...

Answer / Abhinav Awasthi

Here's an example of a simple C program that checks if a number is an Armstrong number. Note that this program assumes the input number to be a positive integer less than 1000 for efficiency.n```n#include <stdio.h>nvoid armstrong(int n){ // function to check armstrong numbertint i, sum = 0, temp = n;n while (temp > 0){ntsum += (temp % 10) * (temp % 10) * (temp % 10);ntemp /= 10;n}n if (sum == n) printf("%d is an Armstrong number.", n);n else printf("%d is not an Armstrong number.", n);n}nint main(){n int num; /* input number */nprintf("Enter a positive integer less than 1000: ");nscanf("%d", &num);narmstrong(num);nreturn 0;n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Write a program for deleting duplicate elements in an array

3 Answers   Subex,


Output for following program using for loop only * * * * * * * * * * * * * * *

3 Answers  


which operator is known as dummy operator in c?

2 Answers   Wipro,


printf(), scanf() these are a) library functions b) userdefined functions c) system functions d) they are not functions

1 Answers  


What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

1 Answers  


What is volatile

2 Answers  


WRITE A PROGRAM IN C TO MULTIPLY TWO 2-D ARRAYS

4 Answers  


What is output of the following program ? main() { i = 1; printf("%d %d %d\n",i,i++,i++); }

9 Answers   CTS, Wipro,


the operator for exponencation is a.** b.^ c.% d.not available

5 Answers   TCS,


What is a floating point in c?

1 Answers  


what is available in C language but not in C++?

10 Answers   CTS, TCS,


What is the advantage of using #define to declare a constant?

1 Answers   Agilent, ZS Associates,


Categories