0
i am trying to impliment amstrong no code but my if statement is not executing why?
#include<stdio.h> int main() { printf("type the no "); int a,b,c,n=0; scanf("%d",&a); for(;a>0;a=a/10) {b=a%10; c= b*b*b; n=n+c; } if(n==a) printf("yes"); }
3 Antworten
+ 1
Cause n!=a
+ 1
Your input into a finally changing to 0.
So
You should copy input and compare that with n.
You don't write any part to see wrong input for armstring.. So if you give input which is armstring then if gets executed otherwise don't.
What input you are trying?
+ 1
Firstly your code will work only for 3-digit numbers. Secondly, variable a is changing in for loop.