Welcome to codechef. I’ll be your guide.
The age of Turbo C++ ended a long time ago, along with the use of .h
after header files. For the new C++, we do not use <iostream.h>
, we instead use <iostream>
and after the headers add a using namespace std;
. We no longer need to add the .h
. For native C headers, we add a c before the header, for example, <stdio.h>
in C++ becomes <cstdio>
and <string.h>
becomes <cstring>
( there is also a new header <string>
in C++, do not mix it with <cstring>
) , and so on.
Also, void main()
is no longer accepted according to the C++ standard. You must use int main()
. You can use void main()
on Turbo C++, but not on newer versions. You must use int main()
and also have a return 0;
( most new compilers will be okay even if you skip the return 0
in main()
)
Also, some headers like <conio.h>
( so no using getch()
or clrscr()
) and <dos.h>
are not pat of the standard, so don’t use them. Here’s a list of standard libraries
Let me show you simple Program.
#include<iostream>
using namespace std; // don't forget this
int main()
{
cout << "Hello World";
return 0;
}
You will need a new IDE and compiler other than Turbo C++ to get started with Competitive Programming. I suggest to Download Dev C++ or CodeBlocks ( recommended ) with gcc 4.9.2 ( or gcc 4.8.2 ) for best performances. You can also compile your programs on the codechef IDE or ideone or other online compilers.
While on C++, avoid the use of character arrays. They are unsafe. You can instead use string
. Here’s an example.
string mystring; // declaring strings
cin >> mystring; // accepting strings
cout << mystring; // display string
string str = " Welcome to codechef " // initialization
mystring = "Welcome to " + "codechef"; // no need for `strcat()`
if( str == mystring ) // no need for `strcmp()`
There are also nother features like vectors
, lists
, maps
etc which you can slowly start learning.
Nearly forgot, the problem with you 3rd for loop us that you forgot to add int, simply change it to
for( int i = 2 ; i <= n ; i++ )