I am new user of codechef. I execute this program using C++.But it does not execute on IDE.Why?

#include<iostream.h>
#include<conio.h>
int prefixsum(int i,int a[])
{
int sum=0;
for(int j=0;j<=i;j++)
{
sum+=a[j];
}
return sum;
}
int suffixsum(int i,int a[],int n)
{
int sum=0;
for(int j=n-1;j>=i;j–)
{
sum+=a[j];
}
return sum;
}
void main()
{
// your code goes here
int a[100],b[100],min,n,i,p,t,s,c[10];
clrscr();
cout<<"\n Enter no. of test cases";
cin>>t;
for(s=0;s<t;s++)
{
cout<<“Enter the size of array”;
cout<<"\n";
cin>>n;
cout<<“Enter elements of array”;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
b[i]=prefixsum(i,a)+suffixsum(i,a,n);
}
min=b[0];
p=1;
for(i=1;i<n;i++)
{
//min=b[i];
if(min>b[i])
{
min=b[i];
p=i+1;
}
}
c[s]=p;
}
cout<<"\n Output";
for(s=0;s<t;s++)
{
cout<<"\n";
cout<<c[s];
}
getch();
}

Take a look at this link. In short you are using turbo C standards where as codechef IDE supports GCC.

In windows you can use mingw or on Linux you can use gcc to test your program.
The gcc standards and Turbo C standards are somewhat different which was your problem.
Here is why your program is not working.
#1 Use header files as #include etc. Or you can include bits/stdc++.h which is parent for all header files and you need not to include files again and again.
#2 Use std namespace to avoid naming collisions.
#3 Remove unnecessary functions such as clrscr(); and getch();
#4 Use int main() with return instead of void main() as it needs to return execution value i.e 0 for proper execution.

Here is the code

ONLINE COMPILER IDEONE

I prefer to use codechef official IDE

To make it compile, do this-

  1. #include<iostream.h> \rightarrow #include <iostream>
  2. Remove #include<conio.h> it isnt used anymore.
  3. Add using namespace std;
  4. void main()\rightarrow int main()
  5. Remove functions of conio.h as well. Replace by their alternatives. Like clock() for clrscr() and getc() instead of getch() [Read their syntax]
  6. Remove those unnecessary print statements which will give you WA. Your output is matched for an exact match for expected output by machine, so those print statements are redundant and get WA

Plagiarism is a sin dear. You could have at least changed the ordering from mine. Please make sure not to copy off someone else’s answer. It can lead to your suspension :slight_smile:

Bro I commented before you, when a question have similar error and we both noticed that errors doesn’t mean that i copied you.

Revision history is visible to all :). You added those points minutes after I posted my answer.

Anyways, it was just a warning.

1 Like

I think you might be a school student and that’s why you use turbo c++. You should use GNU C++ to be able to submit in any online judge as Borland has stopped supporting turbo since 2002. A good resource to learn about the necessary changes is here: http://foobar.iiitd.edu.in/turbo.pdf written by the trustworthy guys of IIITD. Its just two page so give it a read before submitting :slight_smile:

What do you want me to do?
I am again saying i didn’t even saw your comment when i posted, I was busy modifying that code you can see that link.
Anyways i already awarded you 1 point that was all i had.
Now Happy?

Never Use #include<conio.h> and getche() while submitting your code

//