# multiplication table

• 02-23-2010
yatesj05
multiplication table
I am having trouble getting an asterisk in the corner of my table... I'm allowing a user to input an integer and the program outputs a multiplication table starting with 1 going to the number the user input. I need an asterisk in the top left corner so instead of looking like:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

it should look like:

* 1 2 3 4 5
1 1 2 3 4 5
2 2 4 6 8 10
3 3 6 9 12 15
4 4 8 12 16 20
5 5 10 15 20 25

any help on getting it there? im using for loops to create the table
• 02-23-2010
laserlight
What is your current code? After all, this sounds as easy as printing one extra row of numbers at the top, but starting with an asterisk. (Oh, and an extra column on the left, but that just repeats the first number for the row.)
• 02-23-2010
yatesj05
Code:

``` #include <stdio.h> int input_number (void); int main(void) { int a,row,column;         a=input_number();         for(row = 1; row <= a ; row++ )                 {                                                for (column = 1; column <=a; column++)                         {                                 printf("%6.d",row*column);                         }                 printf("\n");                 }         return 0; } int input_number(void) { int b;         printf("Input a positive integer ");         scanf("%d",&b);         return b; }```
the problem with just putting a print line at the top is that the user cant control how many integers are contained in the table
• 02-23-2010
laserlight
I suggest that you indent your code a little more consistently:
Code:

```#include <stdio.h> int input_number(void); int main(void) {     int a,row,column;     a=input_number();     for(row = 1; row <= a ; row++ )     {         for (column = 1; column <=a; column++)         {             printf("%6.d",row*column);         }         printf("\n");     }     return 0; } int input_number(void) {     int b;     printf("Input a positive integer ");     scanf("%d",&b);     return b; }```
Now, as I noted earlier, you need to print one more row at the top. Printing this is roughly the same as printing the first actual row, except that you just need to print an asterisk first. You would need to add one more statement in your current outer loop to print that extra left column.
• 02-23-2010
MK27
After you get "a" you print one line.

You also need a line inside the outer loop (before the inner loop) to print the first number (the vertical index) in each row.
• 02-23-2010
yatesj05
Thanks a bunch!
• 04-17-2011
yat
hey all. i was aasign to implement a multiplication table server based on input from client.
here is the exam ple of output.
server:waiting for connection
server:receiving connection from ...
client:4
server:1*4=4
server:2*4=8
server:3*4=12

and so on

client:1*4=4
client:2*4=8
...
and so on

really had no idea bout this. i had search all over the web but most of the answer was about the table of multiplication. plis can u help me with this?
• 04-17-2011
Salem
Beej's Guide to Network Programming for network programming.