1. Six Employees ke Working Hours (Array)
#include <iostream>
using namespace std;
int main() {
int hours[6];
for(int i = 0; i < 6; i++) {
cout << "Enter hours worked by employee " << i+1 << ": ";
cin >> hours[i];
}
cout << "\nHours Worked:\n";
for(int i = 0; i < 6; i++) {
cout << "Employee " << i+1 << ": " << hours[i] << endl;
}
return 0;
}
2. 10 Integers lo aur ≥10 count karo
#include <iostream>
using namespace std;
int main() {
int arr[10], count = 0;
for(int i = 0; i < 10; i++) {
cout << "Enter number " << i+1 << ": ";
cin >> arr[i];
if(arr[i] >= 10)
count++;
}
cout << "Numbers greater than or equal to 10: " << count << endl;
return 0;
}
3. First aur Last Element Swap (1-D Array)
#include <iostream>
using namespace std;
int main() {
int arr[5] = {10, 20, 30, 40, 50};
int temp;
temp = arr[0];
arr[0] = arr[4];
arr[4] = temp;
cout << "Array after swapping:\n";
for(int i = 0; i < 5; i++) {
cout << arr[i] << " ";
}
return 0;
}
4. Two Matrices ka Multiplication (Function)
#include <iostream>
using namespace std;
void multiply(int a[2][2], int b[2][2]) {
int c[2][2] = {0};
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
for(int k = 0; k < 2; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
cout << "Result Matrix:\n";
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
cout << c[i][j] << " ";
}
cout << endl;
}
}
int main() {
int a[2][2] = {{1,2},{3,4}};
int b[2][2] = {{5,6},{7,8}};
multiply(a, b);
return 0;
}
5. Two Matrices ka Addition
#include <iostream>
using namespace std;
void add(int a[2][2], int b[2][2]) {
int c[2][2];
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
c[i][j] = a[i][j] + b[i][j];
}
}
cout << "Sum Matrix:\n";
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
cout << c[i][j] << " ";
}
cout << endl;
}
}
int main() {
int a[2][2] = {{1,2},{3,4}};
int b[2][2] = {{5,6},{7,8}};
add(a, b);
return 0;
}
6. Matrix ka Transpose
#include <iostream>
using namespace std;
int main() {
int a[2][3] = {{1,2,3},{4,5,6}};
int t[3][2];
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 3; j++) {
t[j][i] = a[i][j];
}
}
cout << "Transpose Matrix:\n";
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 2; j++) {
cout << t[i][j] << " ";
}
cout << endl;
}
return 0;
}
7. 2D Array ka Highest Number
#include <iostream>
using namespace std;
int main() {
int a[3][3] = {{3, 8, 1}, {6, 4, 9}, {2, 7, 5}};
int max = a[0][0];
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
if(a[i][j] > max)
max = a[i][j];
}
}
cout << "Highest number is: " << max << endl;
return 0;
}

0 Comments