Examples in c++
Examples in c++
Examples
Q1: first program write in c++ ?
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World!";
return 0;
}
Q2: write a program to calculate a sum of two numbers:
#include<iostream>
using namespace std;
int main()
{
int x=10, y=20,z;
z=x+y;
cout<<"the Result of z is: "<<z;
return 0;
}
Q3: Write a program in c++ to calculate a sum of two numbers entered from
keyboard:
#include<iostream>
using namespace std;
int main()
{
cout << "the prog. for sum two int." << endl;
Lecturer. Othman Atta Ismael ALIraqia University College of Engineering
int x, y, z;
cout << "the x= ";
cin >> x;
cout << "the y= ";
cin>> y;
z = x + y;
cout << "the Result of z is: "<< z;
return 0;
}
Q5: Write a program to calculate the remainder of two numbers and output
the result:
#include<iostream>
using namespace std;
int main()
{
cout << "the prog. for remainder two int." << endl;
int x, y, z;
cout << "the x= ";
cin >> x;
cout << "the y= ";
cin>> y;
z = x%y;
cout << "the Result of z is: " << z;
return 0;
}
Q6: Write a program in c++ to solve the equation: z=(x*y)/w:
#include<iostream>
using namespace std;
int main()
{
cout << "the prog. for solve z=(x*y)/w " << endl;
int x, y, w, z;
cout << "the x= ";
cin >> x;
cout << "the y= ";
cin>> y;
Lecturer. Othman Atta Ismael ALIraqia University College of Engineering
Q7/ Write a program in c++ to calculate What year were you born?
#include<iostream>
using namespace std;
int main()
{
int year, age;
cout << "What age are you? ";
cin >> age;
year = 2021 - age;
cout << "You are " << year << " born.\n";
return 0;
}