0% found this document useful (0 votes)
2 views

LAB Assignment 2

assignent

Uploaded by

unknowngaming727
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)
2 views

LAB Assignment 2

assignent

Uploaded by

unknowngaming727
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/ 6

LAB MANUAL 2

Name: Muhammad Hasnain Fareed


ID: F2023376449
QUESTION 1:
#include <iostream>
using namespace std;

int main() {
int* arr = new int[5];
int sum = 0;

cout << "Enter 5 integers: ";


for (int i = 0; i < 5; i++) {
cin >> arr[i];
sum += arr[i];
}

cout << "The sum of all elements is: " << sum << endl;

delete[] arr;
return 0;
}
QUESTION 2:
#include <iostream>
using namespace std;

int main() {
int* arr = new int[5];
int max, min;

cout << "Enter 5 integers: ";


for (int i = 0; i < 5; i++) {
cin >> arr[i];
}

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;

delete[] arr;
return 0;
}

QUESTION 3:
#include <iostream>
using namespace std;

int main() {
int size;
cout << "Enter the length of the word: ";
cin >> size;

char* word = new char[size + 1];

cout << "Enter the word: ";


cin >> word;

cout << "Reversed word: ";


for (int i = size - 1; i >= 0; i--) {
cout << word[i];
}

cout << endl;

delete[] word;
return 0;
}

QUESTION 4:
#include <iostream>
using namespace std;

int main() {
int size;
cout << "Enter the size of the array: ";
cin >> size;

int* arr = new int[size];

cout << "Enter " << size << " integers: ";
for (int i = 0; i < size; i++) {
cin >> arr[i];
}

cout << "Even numbers in the array: ";


for (int i = 0; i < size; i++) {
if (arr[i] % 2 == 0) {
cout << arr[i] << " ";
}
}
cout << endl;

delete[] arr;
return 0;
}

You might also like