0% found this document useful (0 votes)
69 views3 pages

C++ Programs With Output

The document contains a series of C++ programs that demonstrate basic programming concepts. Each program includes functionality such as inputting user data, performing arithmetic operations, and calculating areas and perimeters of geometric shapes. Sample outputs are provided for each program to illustrate the expected results.

Uploaded by

batebe4159
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)
69 views3 pages

C++ Programs With Output

The document contains a series of C++ programs that demonstrate basic programming concepts. Each program includes functionality such as inputting user data, performing arithmetic operations, and calculating areas and perimeters of geometric shapes. Sample outputs are provided for each program to illustrate the expected results.

Uploaded by

batebe4159
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

Q01: Write a C++ program to input your name and ID, then display them.

#include <iostream>
using namespace std;

int main() {
string name;
int id;
cout << "Enter your name: ";
cin >> name;
cout << "Enter your ID: ";
cin >> id;
cout << "Name: " << name << endl;
cout << "ID: " << id << endl;
return 0;
}
Sample Output:

Enter your name: Maria

Enter your ID: 123

Name: Maria

ID: 123

Q02: Write a C++ program to add two numbers and display the result.
#include <iostream>
using namespace std;

int main() {
int a, b, sum;
a = 10;
b = 20;
sum = a + b;
cout << "Sum: " << sum << endl;
return 0;
}
Sample Output:

Sum: 30

Q03: Write a C++ program to find the average of three numbers.


#include <iostream>
using namespace std;

int main() {
float a = 10, b = 20, c = 30, avg;
avg = (a + b + c) / 3;
cout << "Average: " << avg << endl;
return 0;
}
Sample Output:

Average: 20

Q04: Write a C++ program to calculate the area of a circle using radius.
#include <iostream>
using namespace std;

int main() {
float radius = 5.0, area;
area = 3.1416 * radius * radius;
cout << "Area of circle: " << area << endl;
return 0;
}
Sample Output:

Area of circle: 78.54

Q05: Write a C++ program to calculate the area and perimeter of a triangle using base and

height.
#include <iostream>
using namespace std;

int main() {
float base = 6, height = 4, area, perimeter;
area = 0.5 * base * height;
perimeter = base + height + 5; // assuming third side is 5
cout << "Area: " << area << endl;
cout << "Perimeter: " << perimeter << endl;
return 0;
}
Sample Output:

Area: 12

Perimeter: 15

Q06: Write a C++ program to calculate the area and perimeter of a rectangle.
#include <iostream>
using namespace std;

int main() {
float length = 8, width = 5, area, perimeter;
area = length * width;
perimeter = 2 * (length + width);
cout << "Area: " << area << endl;
cout << "Perimeter: " << perimeter << endl;
return 0;
}
Sample Output:

Area: 40

Perimeter: 26

You might also like