+ 2

Why this simple code is not running? It shows time limit exceeded as output.

#include<stdio.h> #include<conio.h> #include<math.h> void main() { int i,n,s,ss,sss; printf("\n enter the value of n="); scanf("%d",&n); s=0; ss=0; sss=0; for(i=1;i<=n;i++) { s+=i; ss+=i*i; sss+=i*i*i; } printf("\n sum of numbers=%d",s); printf("\n sum of squares=%d",ss); printf("\n sum of cubes=%d",sss); getch(); } https://code.sololearn.com/c3ndxKRE77ar/?ref=app https://code.sololearn.com/c3ndxKRE77ar/?ref=app

16th Sep 2019, 12:39 PM
Shubham Nimase
2 Antworten
+ 1
main method must return int. And your code doesn't need conio.h and math.h. Remove them and getch(),
16th Sep 2019, 1:00 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Thanks for helping. My code run successfully, but this was runned on turbo c and not in this app.
16th Sep 2019, 1:06 PM
Shubham Nimase