C Program to Multiplication table
Introduction:
This C program generates a multiplication table for a given number up to a specified range. It takes user input for the number and the range, and then displays the multiplication table in the console.
Explanation:
- We start by including the necessary header file
#include <stdio.h>
for input and output operations. - The
multiplicationTable
function takes two parameters –number
andupTo
. It prints the multiplication table for the given number up to the specified range. - In the
main
function, we prompt the user to enter the number for which they want the multiplication table and the range up to which the table should be generated. - User inputs are stored in
baseNumber
andtableRange
variables. - The
multiplicationTable
function is then called with the user-provided inputs. - The program concludes by returning 0, indicating successful execution.
Program:
#include <stdio.h> int main() { int a, i; printf("Enter a number: "); scanf("%d",&a); for(i=0; i<=5; ++i) { printf("%d * %d = %d \n", a, i, a*i); } return 0; } }
Output:
Enter a number: 7 7 * 0 = 0 7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35
Conclusion:
This C program demonstrates a simple way to generate a multiplication table based on user input. It incorporates functions to enhance modularity and readability. The program takes advantage of basic input/output operations and a loop to efficiently generate and display the multiplication table. Users can easily understand and modify this program for different requirements.