Question #60017

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.

1. 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.
1

Expert's answer

2016-05-20T06:26:07-0400
#include <iostream>
using namespace std;
int main() {
// Task #1
int num;
cout << "1. Enter number: ";
cin >> num;
if (num % 2 == 0) {
cout << "The number is even." << endl;
} else {
cout << "The number is odd." << endl;
}
// Task #2
int num1, num2;
cout << "2. Enter number 1: ";
cin >> num1;
cout << "Enter number 2: ";
cin >> num2;
if (num1 > num2) {
cout << num1 << " is larger." << endl;
} else if (num2 > num1) {
cout << num2 << " is larger." << endl;
} else {
cout << "The numbers are equal." << endl;
}
// Task #3
int arr[3];
cout << "3. Enter three numbers: ";
cin >> arr[0] >> arr[1] >> arr[2];
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
if (arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
cout << "Sorted: " << arr[0] << " " << arr[1] << " " << arr[2] << endl;
// Task #4
int sum = 0;
for (int i = 1; i <= 100; i++) {
sum += i;
}
cout << "4. The sum is " << sum << "." << endl;
// Task #5
sum = 0;
cout << "5. Enter number: ";
cin >> num;
for (int i = 0; i < num; i++) {
if (i % 2 == 0) {
sum += i;
}
}
cout << "The sum equals " << sum << "." << endl;
// Task #6
cout << "6. Enter number 1: ";
cin >> num1;
cout << "Enter number 2: ";
cin >> num2;
cout << "The average is " << (num1 + num2) / ((float) 2) << "." << endl;
}


The flowcharts you may find here http://code2flow.com/IRJUbE.

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!
LATEST TUTORIALS
APPROVED BY CLIENTS