Code
#include<stdio.h>
#include<math.h.>
int main(){
int num = 0 ;
long checkNum = 0;
int digit;
int digitInNum ;
printf("Enter the number of digits in your number:");
scanf("%d",&digitInNum);
for(int i=0 ; i< digitInNum ; i++){
printf("Enter %d digit of your number:",i+1);
scanf("%d",&digit);
checkNum = checkNum + pow(digit,digitInNum);
printf("%d this is the checkNum after each iteration \n",checkNum);
num = num * 10 + digit;
}
printf("Your number is: %d\n",num);
if((checkNum) == num){
printf("It is amstrong number.");
}else{
printf("Not a amstrong number.");
}
}
Output
Enter the number of digits in your number:3
Enter 1 digit of your number:1
1 this is the checkNum after each iteration
Enter 2 digit of your number:5
125 this is the checkNum after each iteration
Enter 3 digit of your number:3
152 this is the checkNum after each iteration
Your number is: 153
Not a amstrong number.
I tried with other amstrong numbers like 370, 371 it works fine but for 153 and for any other number having 1 and 5 in it the last sum is less than what is intended. I tried to run this on my friend's system (vs code only) and also on online compiler it works fine even for 153 (number having 1 and 5) pls help me. Is there a problem with my system (or with extensions in vs code)?
These are the extensions I have installed currently