This program gives you some idea of formatting the output in C. Here we have used %4d for printing the number. The number 4 defines the width of the output number which helps us to format our output and make it more manageable.
Source Code:
//multiplication table from 1*1 - 12 * 10
// using do while loop
#include <stdio.h>
#include <conio.h>
#define COLMAX 10
#define ROWMAX 12
int main()
{
int row, column, y, i, j;
//clrscr();
row = 1;
printf("------------------------------------------------------------");
printf("\n\t\tMultiplication Table from 1 - 12");
printf("\n------------------------------------------------------------");
printf("\n ");
for(i = 1; i <= COLMAX; i++)
printf("%4d", i);
printf("\n-----------------------------------------------------\n");
do //outer loop for 1 - 12
{
column = 1;
printf("%4d |",row);
do //inner loop for 1 - 10
{
y = row * column;
printf("%4d", y); //formating string
column++; //for the table of each row
}while(column <= COLMAX); //inner loop ends
printf("\n");
row++; //next row
}while(row <= ROWMAX);
printf("----------------------------------------------------------");
getch();
return 0;
}
//multiplication table from 1*1 - 12 * 10
// using do while loop
#include <stdio.h>
#include <conio.h>
#define COLMAX 10
#define ROWMAX 12
int main()
{
int row, column, y, i, j;
//clrscr();
row = 1;
printf("------------------------------------------------------------");
printf("\n\t\tMultiplication Table from 1 - 12");
printf("\n------------------------------------------------------------");
printf("\n ");
for(i = 1; i <= COLMAX; i++)
printf("%4d", i);
printf("\n-----------------------------------------------------\n");
do //outer loop for 1 - 12
{
column = 1;
printf("%4d |",row);
do //inner loop for 1 - 10
{
y = row * column;
printf("%4d", y); //formating string
column++; //for the table of each row
}while(column <= COLMAX); //inner loop ends
printf("\n");
row++; //next row
}while(row <= ROWMAX);
printf("----------------------------------------------------------");
getch();
return 0;
}
Output:
No comments:
Post a Comment