0% found this document useful (0 votes)
24 views9 pages

LAB 10 Ahmad

Programming Task

Uploaded by

ahmad sarfraz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views9 pages

LAB 10 Ahmad

Programming Task

Uploaded by

ahmad sarfraz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Submitted To: Col Aqib Perwaiz/LE Moneeb Abbas.

Submitted by: Ahmad Jamal.


Department: Electrical Engineering.
Syndicate: B
CMS ID: 367607.
Subject: Fundamental of Programming.
Topic: Lab Task 7
College of Electrical and Mechanical Engineering
(CEME).
Task 1
Code:

#include <iostream>

using namespace std;

#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>

using namespace std;

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>

using namespace std;

void Print_Grade(int grade)


{

if (grade >= 91 && grade <= 100)


{
cout <<"A+";
}else if (grade >= 81 && grade <= 90)
{
cout << "A";
}else if (grade >= 71 && grade <= 80)
{
cout << "B+";
}
else if (grade >= 61 && grade <= 70)
{
cout << "B";
}
else if (grade >= 51 && grade <= 60)
{

cout << "C";


}
else if (grade >= 41 && grade <= 50)
{

cout << "D";


}
else
{
cout << "Fail";
}

int main()

int grade;

cout << "Enter grade out of 100 : ";

cin >> grade;

Print_Grade(grade);

return 0;

Output:

You might also like