Answer on Question #60019, Programming & Computer Science / C++ Problem.
Write pseudo code and draw flowchart for each of the problems. Based on your algorithm write a C++ code to perform the required task. Your program should be error free.
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
13. Take an integer from the user and display the factorial of that number
Solution.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
// Task #7
int arr[3];
cout << "7. Enter three numbers: ";
cin >> arr[0] >> arr[1] >> arr[2];
int mi = arr[0];
int ma = arr[0];
int sum = 0;
for (int i = 0; i < 3; i++) {
if (arr[i] < mi) {
mi = arr[i];
}
if (arr[i] > ma) {
ma = arr[i];
}
sum += arr[i];
}
cout << "Min:" << mi << endl;
cout << "Max:" << ma << endl;
cout << "Sum:" << sum << endl;
cout << "Average:" << sum / ((float) 3) << endl;
// Task #8
int r;
cout << "8. Enter number radius: ";
cin >> r;
cout << "The area of the circle is " << M_PI * r * r << endl;
// Task #9
int a, b;
cout << "9. Enter two numbers: ";
cin >> a >> b;
int c = a;
a = b;
b = c;
cout << "Swapped: " << a << " " << b << endl;
// Task #10
cout << "10. Enter two numbers: ";
cin >> a >> b;
a = a + b;
b = a - b;
a = a - b;
cout << "Swapped: " << a << " " << b << endl;
// Task #11
int num;
cout << "11. Enter number: ";
cin >> num;
if (num % 2 == 0) {
cout << "The number is even." << endl;
} else {
cout << "The number is odd." << endl;
}
// Task #12
int new_arr[10];
int count = 0;
cout << "12. Enter 10 number in the range 0 - 100: ";
for (int i = 0; i < 10; i++) {
cin >> new_arr[i];
if (new_arr[i] > 50) {
count++;
}
}
cout << count << " is larger than 50." << endl;
// Task # 13
cout << "13. Enter number: ";
cin >> num;
int prod = 1;
for (int i = 1; i <= num; i++) {
prod *= i;
}
cout << "Factorial: " << prod << ".";
}The flowcharts you may find here http://code2flow.com/QebRGz.