Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C ONLY!!! Question 5 (15 marks). Write a program that stores multiplication tabl

ID: 3606882 • Letter: C

Question

C ONLY!!!

Question 5 (15 marks). Write a program that stores multiplication tables from 1 to 9 in a 2-dimensional array. You should not use scanf to enter the values - each element of the 2D array must be assigned the appropriate value (using assignment statements). It then prompts the user to enter a choice. The choice must be a number between 0 and 9. If the user enters any other number, then the program prints a message saying that it is an invalid number.

If choice entered is 0, the program displays the multiplication tables from 1 to 9 as shown in the sample output below. The output must be exactly as shown below. The line of stars has 80 stars (*) in it. You may use (for tab) and (for newline) to get the correct spacing in the output.

If the choice entered is a number between 1 and 9 (both inclusive), the program must print the muliplication table for that number as shown in the sample input/output below.

Your program must repeat this as long as the user wishes to continue. Please follow the sample input/output for further clarification.

Call your source code file Name the c file "lastnameFirstnameA2Q5.c". (Ritu's file would be called

chaturvediRituA2Q5.c)

Sample Input/ output:

Enter zero (0) to see all multiplication tables from 1 - 9 OR

Enter a specific number between 1 and 9 to see its multiplication table

Enter a choice: 2

Printing multiplication table for 2:

-----------------------------------

2 X 1 = 2

2 X 2 = 4

2 X 3 = 6

2 X 4 = 8

2 X 5 = 10

2 X 6 = 12

2 X 7 = 14

2 X 8 = 16

2 X 9 = 18

Do you wish to continue? Enter y for yes, any othr character for no: y

Enter zero (0) to see all multiplication tables from 1 - 9 OR

Enter a specific number between 1 and 9 to see its multiplcation table

Enter a choice: 0

*this part displays all of the multiplication charts

*when showing all multipication, it should all line up!

Printing Multiplication Tables 1 - 9

********************************************************************************

One Two Three Four Five Six Seven Eight Nine

One 1 2 3 4 5 6 7 8 9

Two 2 4 6 8 10 12 14 16 18

Three 3 6 9 12 15 18 21 24 27

Four 4 8 12 16 20 24 28 32 36

Five 5 10 15 20 25 30 35 40 45

Six 6 12 18 24 30 36 42 48 54

Seven 7 14 21 28 35 42 49 56 63

Eight 8 16 24 32 40 48 56 64 72

Nine 9 18 27 36 45 54 63 72 81

********************************************************************************

Do you wish to continue? Enter y for yes, any other character for no: n

Good Bye.

Explanation / Answer

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main() {
int arr[9][10];
int choice;
for(int i=0;i<9;i++){
for(int j=1;j<10;j++){
arr[i][j]= (i+1)*j;
}   
}
printf("Enter any no ");
scanf("%d",&choice);
if(choice>9)
printf("invalid no");
if(choice ==0){
for(int i=0;i<9;i++){
for(int j=1;j<10;j++){
printf("%d ",arr[i][j]);
}
printf(" ");
}
}
if(choice<10&&choice>0){
for(int i=1;i<10;i++){
printf("%d * %d = %d",choice,i,arr[choice-1][i]);
printf(" ");
}
}
  
  
return 0;
}