You must have learn multiplication tables in your school days.
This C program asks user to input a number to display its multiplication table. This can be easily achived using a for loop.
Variables :
1.
number : (Datatype int) : to hold a number entered by user.
2.
i : (Datatype int) : is assigned a initial value as 0. This variable is used for iteration
Loop :
One
for loop is used to compute the multiplication table for the inputted number.
Functions :
printf() : is used to display something on the console/screen. Format specifier %d in printf function is used to display a int variable on screen. \n is used to add a newline
scanf() : is used to fetch data inputted by the user on the console/screen using keyboard.
%d in scanf is indicates that inputted text is of type int.
/*
* 1000+ C programs + tutorials
*
*
* 18_compute_math_calcuation_table.c
*
*
* Created on: Oct 20, 2014
* Author: Code2care.org
*/
#include <stdio.h>
//#include <conio.h>
void main() {
int number;
int i = 0;
// clrscr();
printf(" Program to Generate Multiplication Table : ");
printf("\n\n Enter number to generate Multiplication Table : ");
scanf("%d", &number);
printf("\n\nMultiplication Table of %d : \n",number);
printf("=============================\n\n");
for(i; i <11 ; i++) {
printf("%d x %d = %ld \n\n",i,number, i*number);
}
// getch();
}
-
Output :
Program to Generate Multiplication Table :
Enter number to generate Multiplication Table :
Multiplication Table of 13 :
=============================
0 x 13 = 0
1 x 13 = 13
2 x 13 = 26
3 x 13 = 39
4 x 13 = 52
5 x 13 = 65
6 x 13 = 78
7 x 13 = 91
8 x 13 = 104
9 x 13 = 117
10 x 13 = 130
You can also achive this by using a
while loop,
/*
* 1000+ C programs + tutorials
*
*
* 18_compute_math_calcuation_table.c
*
* USING WHILE LOOP
*
* Created on: Oct 20, 2014
* Author: Code2care.org
*/
#include
//#include <conio.h>
void main() {
int number;
int i = 0;
// clrscr();
printf(" Program to Generate Multiplication Table : ");
printf("\n\n Enter number to generate Multiplication Table : ");
scanf("%d", &number);
printf("\n\nMultiplication Table of %d : \n",number);
printf("=============================\n\n");
while(i!=11) {
printf("%d x %d = %ld \n\n",i,number, i*number);
i++;
}
// getch();
}
-
Output :
Program to Generate Multiplication Table :
Enter number to generate Multiplication Table :
Multiplication Table of 12 :
=============================
0 x 12 = 0
1 x 12 = 12
2 x 12 = 24
3 x 12 = 36
4 x 12 = 48
5 x 12 = 60
6 x 12 = 72
7 x 12 = 84
8 x 12 = 96
9 x 12 = 108
10 x 12 = 120
The best way to learn C programming is to practice more and more of programs .
Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.
BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.