LAB 10 Ahmad
LAB 10 Ahmad
#include <iostream>
#define SIZE 50
int main()
{
int array[SIZE];
int i, max, min, size;
cout << "Enter size of the array: ";
cin >> size;
cout << "\n Enter " << size << " elements in the array: ";
for (i = 0; i < size; i++)
cin >> array[i];
max = array[0];
min = array[0];
for (i = 1; i < size; i++)
{
if (array[i] > max)
max = array[i];
if (array[i] < min)
min = array[i];
}
cout << "\nMaximum element =" << max << "\n";
cout << "Minimum element =" << min;
return 0;
}
Output:
5
Task 2
Code:
#include <iostream>
bool voting(int n)
{
if (n >= 18)
{
return true;
}
else
return false;
}
int main()
{
int age;
cout << "Enter your Age:";
cin >> age;
voting(age);
if (voting (age))
{
cout << "Eligble for voting";
}else
cout << "Not Eligble for voting";
return 0;
}
Output:
Task 3
Code:
#include <iostream>
using namespace std;
void isPrime(int n) {
int i, flag = 0;
for (i = 2; i <= n / 2; ++i) {
if (n % i == 0) {
flag = 1;
break;
}
}
if (flag == 0)
cout << n << " is a prime number" << endl;
else
cout << n << " is not a prime number" << endl;
}
int main() {
int a;
cout << "Enter the Numebr:";
cin >> a;
isPrime(a);
return 0;
}
Output:
Task 4
Code:
#include<iostream>
int main()
int grade;
Print_Grade(grade);
return 0;
Output: