Answer to Question #336082 in C++ for sami

Question #336082

Receive a number and determine whether it is odd or even.





2. Obtain two numbers from the keyboard, and determine and display which (if either) is the larger of the two numbers.





3. Receive 3 numbers and display them in ascending order from smallest to largest





4. Add the numbers from 1 to 100 and display the sum





5. Add the even numbers between 0 and any positive integer number given by the user.





6. Find the average of two numbers given by the user.





7. Find the average, maximum, minimum, and sum of three numbers given by the user.





8. Find the area of a circle where the radius is provided by the user.





9. Swap the contents of two variables using a third variable.





10. Swap the content of two variables without using a third variable.





11. Read an integer value from the keyboard and display a message indicating if this number is odd or even.





12. read 10 integers from the keyboard in the range 0 - 100, and count how many of them are larger than 50, and display this result







1
Expert's answer
2022-05-02T18:05:08-0400
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
cout << "###############################################################################################" << endl;
cout << "Receive a number and determine whether it is odd or even." << endl;
int num;
cout << "Enter A: ";
cin >> num;
if (num % 2 == 0)
	cout << "Number A odd" << endl;
else
	cout << "Number A even" << endl;
cout << "###############################################################################################" << endl;
cout << "2. Obtain two numbers from the keyboard, and determine and display which (if either) is the larger of the two numbers." << endl;
int x, y;
cout << "Enter X: ";
cin >> x;
cout << "Enter Y: ";
cin >> y;
if (x > y)
	cout << "Number X larger" << endl;
else if (x < y)
	cout << "Number Y larger" << endl;
else
	cout << "X = Y" << endl;
cout << "###############################################################################################" << endl;
cout << "3. Receive 3 numbers and display them in ascending order from smallest to largest" << endl;
    int a, b, c;
    cout << "Enter A, B, C: ";
    cin >> a >> b >> c;
    if (a > b)
        swap(a, b);
    if (b > c)
        swap(b , c);
    if (a > b)
        swap(a ,b);
    cout << a << ' ' << b << ' ' << c << endl;
cout << "###############################################################################################" << endl;
cout << "4. Add the numbers from 1 to 100 and display the sum" << endl;
int sum = 0, i = 0;
for(i = 1; i <= 100; i++)
	sum += i;
cout << "Sum from 1 to 100 = " << sum << endl;
cout << "###############################################################################################" << endl;
cout << "5. Add the even numbers between 0 and any positive integer number given by the user." << endl;
int k, sum2;
cout << "Enter K: ";
cin >> k;
for(int i = 0; i <= k; i++)
	if(i % 2 == 0)
		sum2 += i;
cout << "Sum even numbers between 0 and K = " << sum2 << endl;
cout << "###############################################################################################" << endl;
cout << "6. Find the average of two numbers given by the user." << endl;
float t, p, average;
cout << "Enter T: ";
cin >> t;
cout << "Enter P: ";
cin >> p;
cout << "The average of two numbers: ";
cout << fixed << setprecision(1) << (t+p)/2 << endl;
cout << "###############################################################################################" << endl;
cout << "7. Find the average, maximum, minimum, and sum of three numbers given by the user." << endl;
float num1, num2, num3;
    cout << "Enter A, B, C: " << endl;
    cin >> num1 >> num2 >> num3;
    if (num1 > num2)
        swap(num1, num2);
    if (num2 > num3)
        swap(num2 , num3);
    if (num1 > num2)
        swap(num1 ,num2);
    cout << "Average = " << setprecision(2) << (num1 + num2 + num3)/3 << endl;
    cout << "Maximum = " << setprecision(0) << num3 << endl;
    cout << "Minimum = " << setprecision(0) << num1 << endl;
    cout << "Sum = " << fixed << setprecision(0) << num1 + num2 + num3 << endl;
cout << "###############################################################################################" << endl;
cout << "8. Find the area of a circle where the radius is provided by the user." << endl;
float R;
cout << "Enter radius: ";
cin >> R;
cout << "The area of a circle: " << M_PI*pow(R,2) << endl;
cout << "###############################################################################################" << endl;
cout << "9. Swap the contents of two variables using a third variable." << endl;
int g, j, tmp;
cout << "Enter G: ";
cin >> g;
cout << "Enter J: ";
cin >> j;
cout << "You enter G=" << g << " J=" << j << endl;
tmp = g;
g = j;
j = tmp;
cout << "     Swap G=" << g << " J=" << j << endl;
cout << "###############################################################################################" << endl;
cout << "10. Swap the content of two variables without using a third variable." << endl;
int v, w;
cout << "Enter V: ";
cin >> v;
cout << "Enter W: ";
cin >> w;
cout << "You enter V=" << v << " W=" << w << endl;
v = v + w;
w = v - w;
v = v - w;
cout << "     Swap V=" << v << " W=" << w << endl;
cout << "###############################################################################################" << endl;
cout << "11. Read an integer value from the keyboard and display a message indicating if this number is odd or even." << endl;
int value;
cout << "Enter value: ";
cin >> value;
if (value % 2 == 0)
	cout << "Number is odd" << endl;
else
	cout << "Number is even" << endl;
cout << "###############################################################################################" << endl;
cout << "12. read 10 integers from the keyboard in the range 0 - 100, " << endl;
cout << "and count how many of them are larger than 50, and display this result" << endl;
int val, AR[10], s = 1, count2 = 0;
cout << "Enter 10 numbers from 0 to 100!!!" << endl;
while (s <= 10){
	cin >> val;
	if (val >= 0 && val <= 100){
		AR[s] = val;
		s ++;
		if (val > 50)
			count2 ++;
	}
	else
		cout << "You need to enter numbers from 0 to 100!!!" << endl;
}
cout << "How many entered numbers are greater than 50? \nANSWER: " << count2 << endl;
cout << "\n#####################################   E   N   D   ###########################################" << endl;	
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS