0% found this document useful (0 votes)
22 views5 pages

Codesnew

Uploaded by

naitiknagargoje
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)
22 views5 pages

Codesnew

Uploaded by

naitiknagargoje
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/ 5

Q.1.

write c ++ program to perform given operations two


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

You might also like