C++ First Program

How to write, compile and run the C++ program.

Example 1: Write a C++ Program, to print 'Welcome to C++ Programming'.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    cout<<"Welcome to C++ Programming.";
    getch();
}
Welcome to C++ Programming.
Code Explanation:
  • #include<iostream.h> - stands for inputoutputstream, .h - header file. It includes the standard input output library functions like cin, cout.
  • cout<< - is an object which is use to display the data.
  • cin>> - is an object which is use to input data from user.

Example 2: Input two numbers and find sum.

#include<iostream.h>
#include<conio.h>
void main()
{
    int a, b, c;
    clrscr();
    cout<<"Enter 1st Number: ";
    cin>>a;
    cout<<"Enter 2nd Number: ";
    cin>>b;
    c=a+b;
    cout<<"Sum = "<<c;
    getch();
}
Enter 1st Number: 10
Enter 2st Number: 20
Sum = 30

C Language Feedback, Questions, Suggestions, Discussion.