0% found this document useful (0 votes)
15 views

Examples in c++

The document contains a series of C++ programming examples provided by Lecturer Othman Atta Ismael from ALIraqia University College of Engineering. Each example demonstrates basic programming concepts such as outputting text, performing arithmetic operations, and taking user input. The examples cover tasks like calculating sums, differences, remainders, and solving equations.

Uploaded by

mohammedgbr100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Examples in c++

The document contains a series of C++ programming examples provided by Lecturer Othman Atta Ismael from ALIraqia University College of Engineering. Each example demonstrates basic programming concepts such as outputting text, performing arithmetic operations, and taking user input. The examples cover tasks like calculating sums, differences, remainders, and solving equations.

Uploaded by

mohammedgbr100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lecturer.

Othman Atta Ismael ALIraqia University College of Engineering

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;
}

Q4: Write a program to calculate the difference between two numbers:


#include<iostream>
using namespace std;
int main()
{
cout << "the prog. for difference 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;
}
Lecturer. Othman Atta Ismael ALIraqia University College of Engineering

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

cout << "the w= ";


cin >> w;
z = (x*y) / w;
cout << "the Result of z is: " << z;
return 0;
}

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;
}

You might also like