Important Coding Questions (With C Language + Code Snippet)
Source: Click This Link |
Definition of Armstrong Number:
What is an Armstrong Number? A number is thought of as an Armstrong number if the sum of its own digits raised to the power number of digits gives the number itself.
For example, 153, 370, 371, 407 are three-digit Armstrong numbers
and, 1634, 8208, 9474 are four-digit Armstrong numbers and there are many more.
Input: 1634
Output: 1634 is an Armstrong number.
Input: 152
Output: 152 is not an Armstrong number.
Code Snippet:
#include<stdio.h>
int main() {
int num, originalNum, remainder, result = 0;
printf("Enter a three-digit integer: ");
scanf("%d", &num);
originalNum = num;
while (originalNum != 0) {
remainder = originalNum % 10;
result += remainder*remainder*remainder;
originalNum /= 10;
}
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return 0;
}
Comments
Post a Comment