1
This program allows to calculate the table from up to 10 to a given number x. But in the cycle of the while
after the first iteration it does not enter and jumps to the end. For example, if I insert 2 my output is:
Introduza o numero da tabuada que quer!
3
tabuada do 0
0x3=0
1x3=0
2x3=0
3x3=0
4x3=0
5x3=0
6x3=0
7x3=0
8x3=0
9x3=0
10x3=0
tabuada do 1
tabuada do 2
tabuada do 3
The code that generates the above output is as follows:
void main()
{
int i,x, a, resultado;
printf(" Introduza o numero da tabuada que quer!\n\n");
scanf("%d", &a);
i = 0;
x = 0;
do {
printf(" tabuada do %d\n\n", x);
{
while (i <= 10)
{
resultado = i*x;
printf(" %dx%d=%d\n", i, a, resultado);
i++;
}
}
x++;
} while (x <= a);
}
You need to get back the
i
for0
after printing the first times table.– bfavaretto
But if you only want to tabulate the number typed, I did not understand why there is the outside loop (the
do..while
)– bfavaretto
I want all tabs to the number typed
– kingwarrior05
I’ve noticed the error, thank you :)
– kingwarrior05
The problem is that you are considering the position of the table as the starting point of your calculation, and not the type of table you want to perform the calculation. This way whenever you choose one of them it will continue the loop from this position until the end.
– Ivan Ferrer