0

Why 153 is not printing even when it is an Armstrong number??

This is a code to print Armstrong number. But the number 153 is not printing in VS code but it is working fine in other code editors. #include <stdio.h> #include <math.h> void main() { int num, originalNum, remainder, counter=0, result=0; printf("Armstrong number between 1 to 1000:\n"); for(num = 1; num <=1000; num++) { originalNum = num; while(originalNum != 0) { originalNum = originalNum/10; counter++; } originalNum = num; while(originalNum != 0) { remainder = originalNum % 10; result = result + pow(remainder,counter); originalNum = originalNum / 10; } if(result == num) { printf("%d\n",num); } result = 0; counter = 0; } } Please tell how to fix this issue?

12th May 2023, 2:52 AM
Jainil Raval
Jainil Raval - avatar
6 Answers
+ 2
Can you show your output with expected output?...
12th May 2023, 9:14 AM
Jayakrishna 🇼🇳
+ 1
The low-hanging answer is that you probably have a typo in the VS Code version. Is this copy/pasted directly from that?
12th May 2023, 3:23 AM
Orin Cook
Orin Cook - avatar
0
15th May 2023, 3:36 PM
Jainil Raval
Jainil Raval - avatar
0
Jayakrishna 🇼🇳 The expected output is: 1 2 3 4 5 6 7 8 9 153 370 371 407
15th May 2023, 3:37 PM
Jainil Raval
Jainil Raval - avatar
0
Well idk what to tell you then, cause it works fine for me just c/p-ed from here as-is (it complains that main should return int, cause the playground is picky about that, but it still runs fine).
15th May 2023, 6:30 PM
Orin Cook
Orin Cook - avatar
0
Jayakrishna 🇼🇳 My output is: 1 2 3 4 5 6 7 8 9 370 371 407
16th May 2023, 1:27 AM
Jainil Raval
Jainil Raval - avatar