+ 7

What is wrong in this code?

This is a program to find superperfect no.s from 1 to n. Superperfect no(say a) is the one, sum of whose divisors =x(say) Then, Sum of divisors of x=a*2 The code us written in C.. #include <stdio.h> #include <conio.h> int super(int a) { int sum=0,b; for(b=1;b<=a;b++) { if(a%b==0) sum=sum+b; } return sum; } int main() { int n; scanf("%d",&n); int i; for(i=1;i<=n;i++) { int c=super(i); int d=super(c); if(d==i*2) printf("%d",i); } } Thanks

29th Aug 2017, 11:11 AM
Abhishek Tandon
Abhishek Tandon - avatar
5 Antworten
+ 4
First, scanf does not seems to work on sololearn playground .... Second, conio.h might not be recognized here either and is a windows only library Third, declaring variables in the for loop or just after any statement is bad practice in C and does not compile if you compile it with ANSI C. Last, you forgot the return 0; statement :)
29th Aug 2017, 12:14 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 7
Hey @Prunier The code is running now!
29th Aug 2017, 1:39 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 7
@Lordkrishna He Bhagwan! Javascript ka tag hata diya gaya hai. Galti ke liye kshama mangte hai...
29th Aug 2017, 1:44 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 5
Thanks @Prunier. But still wondering why my other codes worked well even without return 0. Why is it so??
29th Aug 2017, 1:41 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 2
@ATD the compiler can have added it by default, I do not know and can't know without seeing the code :/ Even seeing them can not be enough to find out ^^
29th Aug 2017, 1:48 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar