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/ 5
Q.1.
write c ++ program to perform given operations two
input integers. CODE : #include <iostream> using namespace std; int main() { int a = 2; int b = 4; cout << "Addition: " << a + b << endl; cout << "Subtraction: " << a - b << endl; cout << "Multiplication: " << a * b << endl; cout << "Division: " << a / b << endl; cout << "Modulus: " << a % b << endl; cout << "Increment (a): " << ++a << endl; cout << "Decrement (b): " << --b << endl; return 0; } Q.2. Write a C++ code for calculating the Average and The Percentage of the Students marks. CODE: #include <iostream> using namespace std; int main() { int marks[5]; int total = 0; float average, percentage; cout << "Enter marks for 5 subjects: "; for (int i = 0; i < 5; ++i) { cin >> marks[i]; total += marks[i]; } average = total / 5.0; percentage = (total / 500.0) * 100; cout << "Total Marks: " << total << endl; cout << "Average Marks: " << average << endl; cout << "Percentage: " << percentage << "%" << endl; return 0; } Q.3. Write C++ program to swap two numbers. CODE: #include <iostream> using namespace std; int main() { int a, b, temp; cout << "Enter two numbers:\na:\nb:\n "; cin >> a >> b; // Swapping process temp = a; a = b; b = temp; cout << "After swapping, a = " << a << " and b = " << b << endl; return 0; } Q.4 Write C++ program to display array of 10 numbers. CODE: #include <iostream> using namespace std; int main() { int numbers[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; cout << "Array elements are:"; for (int i = 0; i < 10; ++i) { cout << numbers[i] << "\n "; } cout << endl; return 0; } Q.5 Write cpp program to perform addition of 2 matrices CODE : #include <iostream> using namespace std; int main() { int matrix1[3][3] = {{1, 2, 3},{4, 5, 6},{7, 8, 9}}; int matrix2[3][3] = { {9, 8, 7}, {6, 5, 4}, {3, 2, 1}}; int sum[3][3]; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { sum[i][j] = matrix1[i][j] + matrix2[i][j]; } } cout << "Sum of the matrices:" << endl; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { cout << sum[i][j] << " "; } cout << endl; } return 0; }