You are on page 1of 4

UNIVERSITY OF ENGINEERING AND

TECHNOLOGY TAXILA
ELECTRICAL ENGINEERING DEPARTMENT

Assignment No#13
For the Course of
Programming Fundamental

For
First Semester
Electrical Engineering Department
(B.Sc. Electrical Engineering)

Instructor: Engr. M.Qamas. Gul

Submitted by: _____Muhammad Aqib _____________________


Reg. Number: __________19-EE-194____________________________
Section: ____________( B )__________________________
Question #1

Solution :
#include<iostream>
using namespace std;
void GetPrime(int, int);

int main() {
int num1, num2;
cout << "Please Enter 1st Number: ";
cin >> num1;
do
{
cout << "Please Enter 2nd number(must greater or = to " << num1 << " ): ";
cin >> num2;
if (num2 < num1)
cout << "------You Enter an Invalid number----TRY AGAIN\n";
} while (num2 < num1);
GetPrime(num1, num2);
return 0;
}

void GetPrime(int a, int b)


{
bool flag = true;
for (int i = a + 1; i < b; i++)
{
for (int j = 2; j <= i / 2; j++)
{
if (i % j == 0)
{
flag = false;
break;
}
}

if (flag == true)
{
cout << "\n" << i;
}
flag = true;
}
}
After Compiling :

Question # 2

Solution :
#include<iostream>
using namespace std;
int main()
{
int x , sum = 0;
cout << "Enter the number of values :";
cin >> x;
int array['x'] ;
for (int index = 0; index < x; index++)
{
cout << "Enter the" << index+1 << "st value :";
cin >> array[index];
}
for (int index = 0; index < x; index++)
{
sum = sum + array[index];
}
double total, average;
total = x; //
average = sum / total;
cout << endl << "The sum of number is:" << sum << endl;
cout << "The average of your number is :" << average << endl;
return 0;
}

After Compiling :

You might also like