cplusplus-training/Teil_1/4. Kontrollstrukturen/Lösungen/Loesung Uebung 1 - Einmaleins.cpp
2021-10-15 08:36:02 +02:00

65 lines
776 B
C++

#include <iostream>
using namespace std;
void printTableFor();
void printTableWhile();
void printTableDoWhile();
int main(int argc, char** argv)
{
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 printTableWhile()
{
int max = 10;
int i = 1, j = 1;
while(i <= 10)
{
while(j <= 10)
{
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 <= 10);
j = 1;
cout << endl;
i++;
} while(i <= 10);
}