0
This code is running on sololearn,programmiz with correct output. If I give input 153 output is "it is Armstrong number" but
When using in vs code and gcc compiler only showing "not Armstrong number" for 153 only when it is a Armstrong number. Code is ------#include<stdio.h> #include <math.h> int main() { int i,a,x,rem,c=0,j; printf("Enter the number: "); scanf("%d",&a); x=a; for(i=1;i<100;i++){ a=a/10; if(a==0) break; } a=x; for(j=1;j<100;j++){ rem=a%10; c=c+pow(rem,i); a=a/10; if (a==0) break; } if(c==x) printf("It is an Armstrong number."); else printf("It is not an Armstrong number."); }
6 Answers
+ 2
Do you mean "it is outputting -not arnstrong numerous"?
Do other program running currectly?
Do check after taking the value is accepting properly by printing?
printf("%d", a );
Recheck you code again.. Code is fine.
+ 2
Aditya Ghosh do you mean the code doesn't work when compiled by gcc?
I think both sololearn and programiz using gcc, version 10.2.0 and 9.3.0 respectively.
+ 1
What input is you are giving?
0
153
0
Yes it is running correctly in online or other compilers than gcc.
0
If you are using int main(), you need to return an integer (typically 0 to denote successful program execution). Other than that, there is no problem with logic. While loop could be used instead of breaking for loop.
You can try void main or return 0, though I doubt that is why gcc compiler gives wrong output.