Skip to content

Instantly share code, notes, and snippets.

@twopoint718
Created June 20, 2009 01:02
Show Gist options
  • Save twopoint718/132981 to your computer and use it in GitHub Desktop.
Save twopoint718/132981 to your computer and use it in GitHub Desktop.
multiplication table in C
#include <stdio.h>
#include <stdlib.h>
/* a simple multiplication table */
int main()
{
char *cp;
char buffer[256];
printf("Enter a number:\n");
cp = fgets(buffer, 256, stdin);
int num = 0;
if (cp != NULL)
{
num = atoi(cp);
printf("Table size: %d\n", num);
}
int row, col;
for (row = 1; row < num+1; row++)
{
for (col = 1; col < num+1; col++)
{
printf("%3d ", row*col);
}
printf("\n");
}
return 0;
}
@Chapmanalex
Copy link

Please some explanations

@twopoint718
Copy link
Author

It should really be named something like table.c. It's just a simple script (I was probably working on my C at the time and just wanted to test-compile something). Here's what it does:

> clang gist.c -o gist
> ./gist 
Enter a number:
5
Table size: 5
  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 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment