I started to code a really simple task but I keep getting the wrong output. Help me, I'm desperate! The problem is: I have to print a table 4*10. The numbers in the table go from 1 to 40 and they are ascending- the table looks like this:
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
My task is to replace the every other multiple of 3 ( 3, 9, 15) is by the number 2. Every multiple of 5 that hasn't already been used is replaced by the number 3. Everything else is replaced by 1.
#include<cstdio>
#include<cstring>
using namespace std;
int table[10][4];
int i,j;
int br;
int main()
{
br=1;
for(i=0;i<4;i++)
for(j=0;j<10;j++)
{
if(br%6==3) table[i][j]=2;
else if(br%5==0 && br%6!=3) table[i][j]=3;
else table[i][j]=1;
br++;
}
for(i=0;i<4;i++)
{for(j=0;j<10;j++)
{
printf("%d",table[i][j]);
}
printf("\n");
}
return 0;
}
The output I keep getting :
1121111121
1111211111
2111112131
1121311123
The output I should get:
1121311123
1111211113
2111312113
1121311123
g++ -Wall -g) and use the debugger (e.g.gdb)