multiplication table in c
Multiplication Table in C
Here's a simple C program to generate a multiplication table. This program will prompt the user to enter a number and then display the multiplication table for that number from 1 to 10.
#include <stdio.h>
int main() {
int num, i;
printf("Enter a number: ");
scanf("%d", &num);
for (i = 1; i <= 10; i++) {
printf("%d %d = %d\n", num, i, num i);
}
return 0;
}
Explanation of the steps:
1. Include Header File: The program starts by including the standard input-output header file stdio.h
to enable input and output operations.
Main Function: The
main
function is the entry point of the program.Variable Declaration: Inside the
main
function, two variables are declared:num
to store the user input andi
for the loop iteration.User Input: The program prompts the user to enter a number using
printf
and reads the input usingscanf
.Multiplication Table: A
for
loop is used to iterate from 1 to 10. Within the loop, the program prints the multiplication table for the entered number using the format specifier%d
to display the values.Return Statement: Finally, the
main
function returns 0 to indicate successful execution.
This program demonstrates a basic implementation of a multiplication table in C.
[[SOURCE 8]]