Basic Program in C++
Write a program to print a message on the screen?
1 2 3 4 5 6 7 8 | #include<iostream> using namespace std; int main() { cout<<"welcome to dear students"; cout<<"welcome to t4tutorials"; } |
Program with comments.
We can comment the program for better understanding. Comments can be started with the symbols //.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include<iostream> //this is header file to ensure inputs and outputs using namespace std; //here we are adding namespace within the program int main() //this is main function- every program must have a main function. Here this main function is of integer type. { //Starting of main funtion cout<<"welcome to dear students"; //displays the message in double qoutation as: welcome to dear students. cout<<"welcome to t4tutorials"; //displays the message in double qoutation as: welcome to t4tutorials. } //Ending of main funtion |
Output.
Write a program to print two messages on two different lines on the screen?
1 2 3 4 5 6 7 8 | #include<iostream> using namespace std; int main() { cout<<"welcome to dear students"<<endl; cout<<"welcome to t4tutorials"<<endl; } |
Program with comments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include<iostream> //this is header file to ensure inputs and outputs using namespace std; //here we are adding namespace within the program int main() //this is main function- every program must have a main function. Here this main function is of integer type. { //Starting of main funtion cout<<"welcome to dear students"<<endl; //displays the message in double qoutation as: welcome to dear students. Then due to endl control moves to the next line. cout<<"welcome to t4tutorials"<<endl; //displays the message in double qoutation as: welcome to t4tutorials. Then due to endl control moves to the next line. } //Ending of main funtion |
Output of the program.