Share your code and ask specific question.
#include <stdio.h>
int main() {
//num: to store number entered by the user
int num;
//count: to count number of digits
int count = 0;
//i: for looping
int i;
//for calculating sum
int sum = 1, sum2 = 0;
//for storing individual digits
int d = 1;
//tcount, tnum: temporary containers for num and count's original values as it is goimg to be modified in our program
int tcount, tnum;
//Ask the user to input the number
printf("Enter a number: ");
scanf("%d", &num);
//store the original value of 'num' in temporary varible i.e 'tnum'
tnum = num;
//Checking the number of digits in the user input
for(i = 0; num != 0; i++)
{
num = num / 10;
count = count + 1;
}
//reassign the original value of num to tnum as it was modified in the above loop
num = tnum;
tcount = count;
//get the number of digits in the input, now raising the power total number to each digits to check whether it is armstrong number or not
//eg: if the entered number has 3 digits, raise power 3 to each digits and add them
//if it has 4 digits, then raise power 4 to all and sum them
printf("Before: count: %d, Sum: %d\n\n", count, sum);
for(num; num != 0; num = num / 10){
d = num % 10;
for (i = 0; i < count; ++i){
sum = sum * d;
printf("Sum in every loop: %d\n", sum);
sum2 += sum;
//sum = sum + (d * d * d);
}
}
printf("%d \t %d\t%d\n", sum, tnum, sum2);
if(tnum == sum)
printf("%d is armstrong number", tnum);
else
printf("%d is not armstrong number", tnum);
return 0;
}
It is not returning expected results.