Write a C program to output the following multiplication table of a number,when the inputs are keyed in from the keyboard. 5x1=5 5x2=10 5x3=15 ------- ------- 5x10=50
Code: #include<conio.h> #include<stdio.h> main() { float a,b,c; clrscr(); printf("enter a and b values\n"); scanf("%f%f",&a,&b); c=a*b; printf("Multiplication of a and b is:%f",c); getch(); }
Output: enter a and b values 5 1 Multiplication of a and b is: 5 //i.e., the number and multiplier , we asume it as a and b
#include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b; printf("enter value"); scanf("%d", &a); printf("enter value again"); scanf("%d", &b); printf("%d + %d = %d\n", a, b, a*b); getch(); } output enter value 5 enter another value 1 5*1=5
For multiplication table of a number,when the inputs are keyed in from the keyboard: #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b; printf("enter the values"); scanf("%d", &a); scanf("%2d", &b); while(b<=10) { printf("%d * %2d = %2d\n", a, b, a*b); b=b+1; } getch(); } output enter the values 5 1 5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 ........... ........... 5*10=50
Code: #include <stdio.h> #include <string.h> #include <limits.h> int main(void) { char buf[10] = { 0 }; int i, num; do { /* wait for valid numerical input */ printf("Enter table multiplier: "); fgets(buf, sizeof buf, stdin); } while((sscanf(buf, "%d", &num)) != 1); for(i=1; (i * num) < INT_MAX; ++i) { if(i % 10 == 0) { puts("\npress enter"); getchar(); // pause output } printf("%3d %2c %3d = %3d\n", num, 'X', i, i * num); } return 0; } :P