To create a numbers table in C, you can use a simple loop to print the numbers in a formatted way. Here's an example of how to create a multiplication table for numbers 1 to 10:
#include <stdio.h>
int main() {
int i, j;
// Print the header
printf("Multiplication Table\n");
printf("---------------------\n");
// Loop through numbers 1 to 10
for (i = 1; i <= 10; i++) {
for (j = 1; j <= 10; j++) {
printf("%4d", i * j); // Print the product with formatting
}
printf("\n"); // New line after each row
}
return 0;
}
Steps to Compile and Run:
Create a file named
main.c:cd ~/project touch main.cCopy the above code into
main.c.Compile the program:
gcc main.c -o mainRun the program:
./main
This will display a multiplication table from 1 to 10. You can modify the range by changing the loop conditions.
