You are on page 1of 8

SUPERIOR UNIVERSITY

ASSIGNMENT NO. 3
PROGRAMING FUNDANETAL

Academic Year: 2022 – 2026


BS ROBOTICS

Abdul Muizz | Enrollment No.


PF / SIR AHMED BILAL
Date of Submission: March 3, 2023
Q.1: Write a C++ program that input ten number from user using array and display the smallest number?

#include <iostream>

using namespace std;

int main()

{ int num[10], smallest;

// Taking input of 10 numbers

cout << "Enter 10 numbers: ";

for(int i = 0; i < 10; i++)

{ cin >> num[i]; }

// Finding the smallest number

smallest = num[0];

for(int i = 1; i < 10; i++)

{ if(num[i] < smallest)

{ smallest = num[i]; }

// Displaying the smallest number

cout << "The smallest number is: " << smallest << endl;

return 0;

}
Q2: Write a C++ program that input ten number from user using array and display the largest number?

#include <iostream>

using namespace std;

int main()

{ int num[10], largest;

// Taking input of 10 numbers

cout << "Enter 10 numbers: ";

for(int i = 0; i < 10; i++)

{ cin >> num[i]; }

// Finding the largest number

largest = num[0];

for(int i = 1; i < 10; i++)

{ if(num[i] > largest)

{ largest = num[i]; } }

// Displaying the largest number

cout << "The largest number is: " << largest << endl;

return 0;

}
Q3: Take 10 integer inputs from user and store them in an array. Again, ask user to give a number. Now, tell user
whether that number is present in array or not.?

#include <iostream>

using namespace std;

int main()

{ int num[10], search;

// Taking input of 10 numbers

cout << "Enter 10 numbers: ";

for(int i = 0; i < 10; i++)

{ cin >> num[i]; }

// Asking user for input number to search

cout << "Enter a number to search: ";

cin >> search;

// Checking if the search number is present in the array

bool found = false;

for(int i = 0; i < 10; i++)

{ if(num[i] == search)

{ found = true;

break; } }

// Displaying the result

if(found)

{ cout << "The number " << search << " is present in the array." << endl; }

else

{ cout << "The number " << search << " is not present in the array." << endl; }

return 0;

}
Q4: Take 10 integer inputs from user and store them in an array. Now, copy all the elements in another array but in
reverse order?

#include <iostream>

using namespace std;

int main()

{ int num[10], revNum[10];

// Taking input of 10 numbers


cout << "Enter 10 numbers: ";

for(int i = 0; i < 10; i++)

{ cin >> num[i]; }

// Copying the elements in reverse order

for(int i = 0; i < 10; i++)

{ revNum[i] = num[9 - i]; }

// Displaying the reversed array

cout << "The reversed array is: ";

for(int i = 0; i < 10; i++)

{ cout << revNum[i] << " "; }

cout << endl;

return 0; }

Q5: Write a program that input ten number form user using array and find the sum and product of all elements of an
array?

#include <iostream>

using namespace std;

int main()

{ int num[10];

int sum = 0;
int product = 1;

// Taking input of 10 numbers

cout << "Enter 10 numbers: ";

for(int i = 0; i < 10; i++)

{ cin >> num[i]; }

// Calculating sum and product of all elements

for(int i = 0; i < 10; i++)

{ sum += num[i];

product *= num[i]; }

// Displaying the sum and product

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

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

return 0; }

Q6: Write a C++ program to find the second lowest and highest numbers in a given array?

#include <iostream>
#include <algorithm>

using namespace std;

int main() {

int num[10];

// Taking input of 10 numbers

cout << "Enter 10 numbers: ";

for(int i = 0; i < 10; i++)

{ cin >> num[i]; }

// Sorting the array

sort(num, num+10);

// Displaying the second lowest and highest numbers

cout << "The second lowest number is: " << num[1] << endl;

cout << "The second highest number is: " << num[8] << endl;

return 0;

You might also like