0
this is code of armstrong no. by take something return something method but errors are coming please suggest ways to correct it
#include <stdio.h> int arm(int); int main(){ int n,A; printf("enter no"); scanf("%d",&n); A=arm(n); if(A==n) printf ("armstrong no."); else printf ("not armstrong no."); getchar();} int arm (int y) { int temp,r,sum=0; temp=y; while(y!=0){ r=y%10; sum=sum+r*r*r; y=y/10; } return(y);}
2 Antworten
+ 1
Return <sum> instead of <y>
But I think `sum = sum + r * r " r` is only good when input given is a 3-digit number. If the number has different number of digit, you need to count the digit of number <y> (let's say <digits>), then multiply each digit <r> by <digits>.
0
unnati priya
Nothing wrong in your logic
Only thing you have to do return sum instead of y. And also why temp variable ,no need of it.