i am trying to impliment amstrong no code but my if statement is not executing why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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"); }

18th Aug 2020, 4:42 PM
Ashok Kamble
Ashok Kamble - avatar
3 Answers
+ 1
Cause n!=a
18th Aug 2020, 5:11 PM
Marina Vasilyova
Marina Vasilyova - avatar
+ 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?
18th Aug 2020, 5:15 PM
Jayakrishna 🇮🇳
+ 1
Firstly your code will work only for 3-digit numbers. Secondly, variable a is changing in for loop.
18th Aug 2020, 5:27 PM
Marina Vasilyova
Marina Vasilyova - avatar