LAB MANUAL 1
Name: Muhammad Hasnain Fareed
ID: F2023376449
QUESTION 1:
#include <iostream>
using namespace std;
int main() {
int arr[] = {1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < 5; i++) {
sum += arr[i];
}
cout << "The sum of all elements is: " << sum << endl;
return 0;
}
QUESTION 2:
#include <iostream>
using namespace std;
int main() {
int arr[] = {1, 2, 3, 4, 5};
int max, min;
max = min = arr[0];
for (int i = 1; i < 5; i++) {
if (arr[i] > max) max = arr[i];
if (arr[i] < min) min = arr[i];
}
cout << "Maximum value is: " << max << endl;
cout << "Minimum value is: " << min << endl;
return 0;
}
QUESTION 3:
#include <iostream>
using namespace std;
int main() {
int arr[] = {1, 2, 3, 4, 5};
int count = 0;
for (int i = 0; i < 5; i++) {
count++;
}
cout << "The size of the array is: " << count << endl;
return 0;
}
QUESTION 4:
#include <iostream>
using namespace std;
int main() {
char word[] = "Hello";
int size = 5;
cout << "Reversed word: ";
for (int i = size - 1; i >= 0; i--) {
cout << word[i];
}
cout << endl;
return 0;
}
QUESTION 5:
#include <iostream>
using namespace std;
int main() {
int arr[] = {1, 2, 3, 4, 5};
int size = 5;
cout << "Even numbers in the array: ";
for (int i = 0; i < size; i++) {
if (arr[i] % 2 == 0) {
cout << arr[i] << " ";
}
}
cout << endl;
return 0;
}
QUESTION 6:
#include <iostream>
using namespace std;
int main() {
int marks[3][5] = {
{85, 90, 78, 92, 88},
{76, 85, 84, 91, 89},
{90, 92, 91, 95, 94}
};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) {
cout << marks[i][j] << " ";
}
cout << endl;
}
return 0;
}
QUESTION 7:
#include <iostream>
using namespace std;
int main() {
int marks[3][5] = {
{85, 90, 78, 92, 88},
{76, 85, 84, 91, 89},
{90, 92, 91, 95, 94}
};
for (int i = 0; i < 3; i++) {
int sum = 0;
for (int j = 0; j < 5; j++) {
sum += marks[i][j];
}
double average = sum / 5.0;
cout << average << endl;
}
return 0;
}