Dear CProgramming.com
I am trying to get a program to print the following Cayley table on screen:-
12345678
23456781
34567812
45678123
56781234
67812345
78123456
81234567
The problem is that my code prints this:-
12345678
23456789
345678910
4567891011
56789101112
678910111213
7891011121314
89101112131415
I can see why it is doing this. Its because the variable 'b' reaches 9 and at a this point it needs to be reset to 1.
My code is as follows:-
#include <stdio.h>
int main (void)
{
int a = 1;
int b = 1;
int c = 1;
int d = 1;
printf("Cayley Table\n\r");
while (a<=8)
{
b=d;
for (c=1; c<=8; b=b+1,c=c+1) ***** printf("%d",b);
printf("\n");
d=d+1;
a=a+1;
}
return 0;
}
At the point marked with 5 stars, the line "if(b>=8)b=1" needs to be added, the problem is the compiler comes up with "EXPRESSION SYNTAX" errors. I cannot use any semicolon near this bit of code or the program will not check to see if 'b' has reached 9 before resetting it back to 1 within the loop using variable 'c'.
I did post a suggestion here the day b4 yesterday and have tried what was suggested but
I could not get it to work. Please copy the code into a compiler and try it, you will see then what my problem is.
I have tried for AGES many different ways of trying to get this program to work
but without success. Whoever can help me complete this deserves a medal.
Thank-you once again.
Rob.