-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUse-3-loops-to-create-given-output.cpp
More file actions
88 lines (54 loc) · 1.76 KB
/
Use-3-loops-to-create-given-output.cpp
File metadata and controls
88 lines (54 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//CSC 160 Homework 1 due Feb 26
//Purpose: Write a single complete C++ program which, upon execution,
// will use the three C++ loop contructs to produce output
// exactly as shown.
//Author: Larsen J Close Most recent changes: 2/19/16
#include <iostream> // preprocessor directive
#include <iomanip> // needed for most manipulators
#include <cmath> // needed for sqrt()
using namespace std; // using directive
int main ( void )
{
int x;
int m;
int n;
int s;
int k;
m = 5;
n = 2;
k = 1;
cout << "Using a single for loop to count by threes";
for ( x = 3; x <= 15 ; x = x + 3 ) {
cout << setw(3) << x;
}
cout << "\n\n" << "Using a single while loop to show M%N" << endl;
cout << "M N M%N" << endl;
while( m >= 2 ){
s = m % n;
cout << m << setw(8) << n << setw(8) << s << endl;
m = m - 1;
n = n + 2;
}
cout << "\n\n";
cout << "Using a single do-while loop to skip a number" << endl;
do{
if ( k != 4)
cout << k << setw(3);
k++;
}while(k <= 6);
cout << "\n\n";
system ("pause");
return 0;
} //end main ( )
/* Display for above program
Using a single for loop to count by threes 3 6 9 12 15
Using a single while loop to show M%N
M N M%N
5 2 1
4 4 0
3 6 3
2 8 2
Using a single do-while loop to skip a number
1 2 3 5 6
Press any key to continue . . .
*/