You are on page 1of 11

Quiestion 1

Quiestion 1- A- i x Y
#include<iostream>
#include <math.h>
2 4 90
using namespace std;
int main()
{
0 5 360
int x = 2, y = 10, i = 3;
for (; i > 0; i--) {
x += y % ++x;
y *= pow(i, 2);
i--;
cout << i << "," << x << "," << y << endl;
}
}

The Output is:


Quiestion 1- B-
#include<iostream>
#include <math.h>
using namespace std;
int main()
{
int x, y, counteven, countodd, z;
float t;

t = pow(10, 10);
cout << "Enter your Two Numbers but they must be between 1-10 digits \n";
do {
cin >> x >> y;
} while (x > t || y > t);
counteven = 0;
countodd = 0;
for (int i = 0; i < 11; i++)
{
z = x % 10;
x = x / 10;
if (z % 2 == 0) counteven++;
else countodd++;
if (x== 0) break;
}
cout << "The Firest Number counter is \n" << "Even = " << counteven << "\n ODD = " << countodd
<< endl;
counteven = 0;
countodd = 0;
for (int i = 0; i < 11; i++)
{
z = y % 10;
y = y / 10;
if (z % 2 == 0) counteven++;
else countodd++;
if (y == 0) break;
}
cout << "The Firest Number counter is \n" << "Even = " << counteven << "\n ODD = " << countodd
<< endl;
}
Quiestion 2- A-
#include<iostream>
#include <math.h>
using namespace std;
enum PRICE_CAEGORY { CHEAP = 1, MEDIUM = 30, EXPENSIVE = 100 };
int main()
{
int x;
PRICE_CAEGORY price;
do
{
cout << "Enter The Price It Must Be Positive \n";
do {
cin >> x;
} while (x < 1);
price = (PRICE_CAEGORY)x;
if (price < MEDIUM) cout << "The Price Is CHEAP \n";
else if (price >= MEDIUM && price < EXPENSIVE) cout << "The Price Is MEDIUM \n";
else if (price >= EXPENSIVE) cout << "The Price Is EXPENSIVE \n";
} while (1);
}

----------------------------------------------------------------------------------

Quiestion 2- B-
#include<iostream>
using namespace std;
int main()
{
int x, result=1, sum, counter=1;
cout << "enter positive numbers\n";
do {
cin >> x;
if (x < 0) break;
if (counter % 2 == 1) result *= x;
else if (counter % 2 == 0) result += x;
counter++;

} while (1);
cout << "\n result == " << result << endl;
}

Quiestion 2- C-
int i = 1;
while (i < n) {
cout << i * i << " ";
i++;
}

Quiestion 2- D-
int a = 1, b = 1, c = 0, d = 4;
cout << (d < 5 || a == b && --a == c) << "\n" << a;

The Result Is
1

1
Quiestion 3- A-
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int i = 0, j = 1, k = 2, x, y, n, a1 = 0, a2 = 0, fact = 1, sum = 0, counter = 0;
float a3 = 0, avg;

cout << "enter x then y then n \n";


cin >> x >> y >> n;
for (; i < n; i++) {
a1 += pow(k, 2);
fact *= j;
a2 += fact;
a3 += (float)1 / (pow(x, 2 * i));
if (x < y && x % n == 0)
{
sum += x;
counter++;
}
x++;
j++;
k++;
}
if (counter == 0) avg = 0;
else if (counter != 0)avg = sum / counter;
cout << "a1 = " << a1 << "\n a2 = " << a2 << "\n a3 = " << a3 << "\n avg =" << avg << endl;

Quiestion 3- B-
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int x, i, j;
for (i = 1; i < 5; i++)
{
cin >> x;
if (x < 0) break;
for (j = x; j < x + 2; j++) {
cout << "i=" << i << " , j=" << j << " , X=" << x << endl;
}
}
}
Quiestion 4- A-

#include<iostream>
using namespace std;
int main()
{
int A[2][3]{ 6,12,5,15,3,9 };
int sum = 0;
for (int i = 1; i < 2; i++)
{
for (int j = 0; j<3; j++) {
if ((i + j) % 2 == 0 && A[i][j] % 3 == 0)
sum += A[i][j];
else
sum += 2 * A[i][j];

}
}
cout << "sum=" << sum << endl;
}

Result sum=51

Quiestion 4- B-

#include<iostream>
#include<math.h>
using namespace std;
float f(float x, float n)
{
float sum = 0;
for (int i = 1; i <= n; i++)
{
sum += sqrt(pow(x, 2) + pow(i, 2));
}
return sum;
}
int main()
{
int x, n;
cout << "enter value of x then n \n";
cin >> x >> n;
cout << "f(" << x << "," << n << ") = " << f(x, n) << endl;
}
Quiestion 4- C-

#include <iostream>
using namespace std;
double midRange(int arr[], int size)
{
int max = arr[0], min = arr[0];
for (int i = 1; i < size; ++i)
{
if (arr[i] < min)
min = arr[i];
if (arr[i] > max)
max = arr[i];
}
return (max + min) / 2.00;
}
int main()
{
int a[] = { 2,6,4,7,4,3,5,26,27 };
cout << midRange(a, 9);
}

You might also like