New course! Every coder should learn Generative AI!
Try a free lesson+ 5
hey AMOGHA. A. K.
both are same , but " endl " flushes the output buffer !
ex: newline appears like this : cout<<"\n" ;
and endl appears like this : cout<<"\n" <<flush ;
+ 3
cout << endl; is for adding new line.
Alternatively(shorter):
cout<<" The Simple interest for the amount "<<p<<" for "<<t<<" years @ "<<r<<" % is: "<< i << endl;
+ 3
"endl" just change to the new line . It adds a new line to your program .
For ex: if you use
cout << 1 << endl << 2 << endl << 3 << endl;
output should look like this:-
1
2
3
it just a thing that you want to know where your new cursor is, so just take your cursor as "|" so in previously output
i.e
1
2
3
| <--- after using endl (last one endl ..3rd one)
your cursor is here.
One more thing is that ,
in cpp or C++
"\n" and "endl" are same things.
you can use either any of them.
for ex:-
cout << "\n";
cout << endl;
But, in case if u wonder that which one is fast for performing new line operation...
then that is "\n".
Hope this will help you..
Thanks ..🙂
+ 1
It will be a best option to write. Terminating the code in the new line is not a problem.
Though it depends on you .
0
Endl or "\n " is important in CP and also to check the test cases otherwise it isn't.
For showing output cool we use it. However without that the output looks very haphazard 😂.
Use endl.