Skip to content
Snippets Groups Projects
Commit 58fef0ab authored by Rudi Buss's avatar Rudi Buss
Browse files

Update Solution Exercise 1 - Multiplication tables.cpp

parent ca848714
No related branches found
No related tags found
No related merge requests found
......@@ -6,60 +6,49 @@ void printTableFor();
void printTableWhile();
void printTableDoWhile();
int main()
{
printTableFor();
cout << endl;
printTableWhile();
cout << endl;
printTableDoWhile();
return 0;
int main() {
printTableFor();
cout << endl;
printTableWhile();
cout << endl;
printTableDoWhile();
return 0;
}
void printTableFor()
{
int max = 10;
for(int i = 1; i <= max; i++)
{
for(int j = 1; j <= max; j++)
{
cout << (i*j) << "\t";
}
cout << endl;
}
void printTableFor() {
int max = 10;
for (int i = 1; i <= max; i++) {
for (int j = 1; j <= max; j++) {
cout << (i * j) << "\t";
}
cout << endl;
}
}
void printTableWhile()
{
int max = 10;
int i = 1, j = 1;
while(i <= max)
{
while(j <= max)
{
cout << (i*j) << "\t";
j++;
}
j = 1;
cout << endl;
i++;
}
void printTableWhile() {
int max = 10;
int i = 1, j = 1;
while (i <= max) {
while (j <= max) {
cout << (i * j) << "\t";
j++;
}
j = 1;
cout << endl;
i++;
}
}
void printTableDoWhile()
{
int max = 10;
int i = 1, j = 1;
do
{
do
{
cout << (i*j) << "\t";
j++;
}while(j <= max);
j = 1;
cout << endl;
i++;
} while(i <= max);
void printTableDoWhile() {
int max = 10;
int i = 1, j = 1;
do {
do {
cout << (i * j) << "\t";
j++;
} while (j <= max);
j = 1;
cout << endl;
i++;
} while (i <= max);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment