Introduction to C++
A normal program which help
you to understand the basics of C++.
#include<conio.h> Header
files
#include<iostream.h>
void
main()
{ Function used for basic programe
clrscr();
int number1, number2, sum;
cout<<"Enter the first number
";
cin>>number1;
cout<<"Enter the second number
";
cin>>number2; Main program
sum=number1+number2;
cout<<"The sum is
"<<sum;
getch();
}
Now the explanation of each line
#include<conio.h>
#include<iostream.h>
here, # symbol
is preprocessor directive. it indicates that the specified header file must be
included is the program.
Headers files are special predefined file files in C++ . in above progam <iostream.h> is for input/output ( cin and cout as used in program) statement. And <conio.h> is for clrscr() function and getch() function.
Headers files are special predefined file files in C++ . in above progam <iostream.h> is for input/output ( cin and cout as used in program) statement. And <conio.h> is for clrscr() function and getch() function.
void main()
It is main function and in this program we
have defined void main function means it will not return any value but by
default return value will become integer so we can we can define main function
as per requirement like char main() if we want to return value to be an
character value.
clrscr();
Thish is
for clear the screen .
int number1, number2, sum;
in thish
we have defined three integer which hold uor three integer values.
cout<<"Enter the first number
";
cin>>number1;
cout<<"Enter the second number
";
cin>>number2;
they are
input and output operator by using them
we enter value so that we can get result.
sum=number1+number2;
this
line intialise sum interger with sum of number1 and number2
getch();
this
function prevent the closing of output screen unmtil any key presed by the
user.
Comments
Post a Comment