Sep 12, 2010 at 9:31am UTC
Im new in C++ programming so i dont know the required syntax.
The program is suposed to calculate the addiction S=1^2+2^2+3^2+...+(2n+1)^2
Sep 12, 2010 at 9:46am UTC
this was helpfull, but i still dont understand a thing.
i saw many times that "\n" is used in some programms.
my question is, what does is change ?
is there any difference if i dont use it ?
Sep 12, 2010 at 9:52am UTC
"\n" is a newline escape character:
cout <<"This is a line \nThis is another line" ;
output:
This is a line
This is another line
Without \n output would be
This is a line This is another line
Last edited on Sep 12, 2010 at 9:53am UTC
Sep 12, 2010 at 9:54am UTC
+1 Null
Hmmm.. how much C++ do you know?
Sep 12, 2010 at 10:10am UTC
so is exactly like using this:
1 2 3 4 5 6 7 8
#include<iostream>
int main()
{
cout<<"This is a line" <<endl;
cout<<"This is another line" ;
system("pause" );
return 0;
}
and the output is same just we use 1 row instead of 2. :D
thx. now i finally understoot it.
P.S.: "\n" can be used with "<iostream>" ?
Last edited on Sep 12, 2010 at 10:17am UTC
Sep 12, 2010 at 10:20am UTC
Sure, \n can be use without <iostream> but you cannot use std::cout without it.
Sep 12, 2010 at 10:24am UTC
just let me know if im right
1) "cout" and "cin" are used with "<iosteam>",
2) "printf" is used with "<stdio>".
am i right ?
and last P.S.: i see that some tutorials use <iostream> and others use <iostream.h>;
some tutorials use <math>, others use <math.h>. Im a little confunse. Does the ".h" change something ? or is just the syntax of another version of C++ ?
Last edited on Sep 12, 2010 at 10:26am UTC
Sep 12, 2010 at 10:27am UTC
Yes.
EDIT:
and last P.S.: i see that some tutorials use <iostream> and others use <iostream.h>;
Don't use <iostream.h>, always use <iostream> instead. iostream.h is an old header and not part of C++ standard.
some tutorials use <math>, others use <math.h>.
there's no difference between <cmath> and <math.h> except that <cmath> functions are under std namespace.
Last edited on Sep 12, 2010 at 10:32am UTC
Sep 12, 2010 at 10:37am UTC
thanks again. really apreciated.