Write a program to check armstrong number in c?
Answer / Rebat Singh
An Armstrong number is a number that is equal to the sum of its own digits raised to the power of three. Here's an example C program that checks if a given number is an Armstrong number:
```c
#include <stdio.h>
int calcSum(int n);
int main() {
int num, sum, temp;
printf("Enter a number: ");
scanf("%d", &num);
temp = num;
sum = calcSum(num);
if (sum == temp) {
printf("%d is an Armstrong number.n", num);
} else {
printf("%d is not an Armstrong number.n", num);
}
return 0;
}
int calcSum(int n) {
int sum = 0, rem;
while (n != 0) {
rem = n % 10;
sum += rem * rem * rem;
n /= 10;
}
return sum;
}
```
In this code, the calcSum function calculates the sum of the digits of a given number raised to the power of three. The main function then compares the original number with the calculated sum to determine if it's an Armstrong number.
| Is This Answer Correct ? | 0 Yes | 0 No |
implement general tree using link list
void main() { int *ptr; ptr = (int *) 0x400 ; printf("ptr=%d",ptr); } output?
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
How can my program discover the complete pathname to the executable from which it was invoked?
Explain how do you determine the length of a string value that was stored in a variable?
How do you override a defined macro?
What is the output of the program given below #include<stdio.h> main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
21 Answers ADITI, Student, TCS,
What are local and global variables?
Write a c program using for loop in switch case?
value = 0xabcd; for (loop = 1; (value >> 1) & 1 | loop & 1; loop++) { foo(); if (loop & 1) value >>= 1; } how many times is foo() executed?
how can i include my own .h file EX:- alex.h like #include<alex.h>, rather than #include"alex.h"
what will be the output of this program? void main() { int a[]={5,10,15}; int i=0,num; num=a[++i] + ++i +(++i); printf("%d",num); }