Though this site aims at understanding C language, I am writing a program for you in C++, to have a general idea about C++ too.
A program in C++,to calculate the average of two numbers, which are entered by the keyboard while the execution of the program.
Try to understand the program;
#include < iostream >
using namespace std;
int main()
{
float num1,num2,average,sum;
cout << "Enter the first number:";
cin >> num1;
cout << "Enter the second number:";
cin >> num2;
sum=num1+num2;
average=sum/2;
cout << "The sum of the two numbers is:"<< sum<<"\n"<<"The average of the two numbers is:" << average;
return(0);
}
Explaination:
The new file header used here in this C++ program is the #include. By this , we are asking the preprocessor to add the contents of the iostream file to our program.
The program is written in the main() function , just like in C.
The variables are defined as float in the same manner.
Here in C++ we use cout and cin operators for output and input respectively. These are parallel to the printf and scanf in C.
In the last cout statement the output is cascaded using the cout operator.which is new in the C++ .
As the main() function is integer type , it returns a zero value which is written as return(0)
A program in C++,to calculate the average of two numbers, which are entered by the keyboard while the execution of the program.
Try to understand the program;
#include < iostream >
using namespace std;
int main()
{
float num1,num2,average,sum;
cout << "Enter the first number:";
cin >> num1;
cout << "Enter the second number:";
cin >> num2;
sum=num1+num2;
average=sum/2;
cout << "The sum of the two numbers is:"<< sum<<"\n"<<"The average of the two numbers is:" << average;
return(0);
}
Explaination:
The new file header used here in this C++ program is the #include
The program is written in the main() function , just like in C.
The variables are defined as float in the same manner.
Here in C++ we use cout and cin operators for output and input respectively. These are parallel to the printf and scanf in C.
In the last cout statement the output is cascaded using the cout operator.which is new in the C++ .
As the main() function is integer type , it returns a zero value which is written as return(0)
Comments
http://www.alienweb.in/products/classified-portal.html
please admin just update some article.
http://cprogramming.pickatutorial.com