0
What is wrong with this C program?
I wrote the following C program to find whether a no. is perfect no. but when i run it the compiler crashes and gives msg as test.exe has stopped working. test.c is my file name btw. why? my code:- void perfect(int x); int main() { int x; scanf("%d",&x); perfect(x); return 0; } void perfect(int x) { int i,s=0; for(i=0;i<x;i++) { int r=x%i; if(r==0) s+=i; } if(s==x) printf("Number is perfect"); else printf("Number not perfect"); }
4 Antworten
+ 2
I found it ! You did r % i when i == 0, which is a runtime error
+ 1
000.damn. thanks
0
i have typed that in compiler. here i just posted the main code.
- 1
There should be a
#include <stdio.h>
but without it, it shouldn't even compile so I guess you just forget to copy past it :/