Question: #include using namespace std; / * * * * * * * * * * * * * * * * * * * *

#include
using namespace std;
/*********************************************
Example 1: For loops
**********************************************/
void Example1(){
cout <<"*****************************
";
cout <<"* Example 1:
";
cout <<"*****************************
";
//1.
cout <<"1. Expected Values: 012345"<< endl;
for (int i =0; i <6; i++){
cout << i <<"";
}
cout << endl << endl;
//2.
cout <<"2. Expected Values: 54321"<< endl;
for (int i =0; i <6; i++){
cout << i <<"";
}
cout << endl << endl;
//3.
cout <<"3. Expected Values: 246810"<< endl;
for (int i =0; i <6; i++){
cout << i <<"";
}
cout << endl << endl;
//4.
cout <<"4. Expected Values: 9630"<< endl;
for (int i =0; i <6; i++){
cout << i <<"";
}
cout << endl << endl;
}
/*********************************************
Example 2: While loops
**********************************************/
void Example2(){
cout <<"*****************************
";
cout <<"* Example 2:
";
cout <<"*****************************
";
int high =0;
int low =0;
int num;
do {
cout << "Enter a number: (-1 to quit)";
cin >> num;
if (num ==-1){
break;
}
if (num <1|| num >100){
cout << "Invalid number: "<< num << endl;
}
if (num < low){
low = num;
}
if (num > high){
high = num;
}
cout << "High: "<< high << endl;
cout << "Low: "<< low << endl;
} while (num !=-1);
}
/*********************************************
Example 3: Math logic with loops
**********************************************/
void Example3(){
cout <<"
*****************************
";
cout <<"* Example 3:
";
cout <<"*****************************
";
// Variables
int num, sum =0;
// Inputs
cout << "Enter a number: ";
cin >> num;
// Equations
for (int i =1; i < num; i++){
if (num % i ==0){
sum += i;
}
}
cout << "The sum of the factors of "<< num <<" is "<< sum << endl;
// Determine the number type
}
int main(){
Example1();
// Example2();
// Example3();
}\

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!