Answer to Question #275112 in C for answer

Question #275112

Create a C program that will generate a table of chosen mathematical operations. The user has to be prompted first for the math operation and then enter a value that will be used to add, subtract, multiply or divide from 1 to 10 to complete the table.


Sample Run:

M A T H O P E R A T I O N S:

[M] – Multiplication

[D] – Division

[A] – Addition

[S] - Subtraction

Enter your choice: M

Enter your desired value to be multiplied: 8


1*8=8

2*8=16

3*8=24

4*8=32

5*8=40

6*8=48

7*8=56

8*8=64

9*8=72

10*8=80


Continue [Y/N]? Y


M A T H O P E R A T I O N S:

[M] – Multiplication

[D] – Division

[A] – Addition

[S] - Subtraction


Enter your choice: A

Enter your desired value to be added:4


1+4=5

2+4=6

3+4=7

4+4=8

5+4=9

6+4=10

7+4=11

8+4=12

9+4=13

10+4=14


Continue [Y/N]? N

Thank you for choosing my program


1
Expert's answer
2021-12-03T06:27:52-0500
#include<stdio.h>
int main(){
	char c;
	char choice;
	int value;
	int i;
	do{
		printf("M A T H   O P E R A T I O N S:\n");
		printf("[M] - Multiplication\n");
		printf("[D] - Division\n");
		printf("[A] - Addition\n");
		printf("[S] - Subtraction\n");
		printf("Enter your choice: ");
		fflush(stdin);
		scanf("%c", &choice);
		switch(choice){
		case 'M':
		case 'm':
			printf("Enter your desired value to be multiplied: ");
			scanf("%d", &value);
			printf("\n\n");
			for( i=1; i<=10; i++){
				printf("%d * %d = %d\n", value, i, (i*value));
			}
			break;
		case 'D':
		case 'd':
			printf("Enter your desired value to be divided: ");
			scanf("%d", &value);
			printf("\n\n");
			for(i=1; i<=10; i++){
				printf("%d / %d = %.2f\n", value, i, ((float)value/(float)i));
			}
			break;


		case 'A':
		case 'a':
			printf("Enter your desired value to be added: ");
			scanf("%d", &value);
			printf("\n\n");
			for( i=1; i<=10; i++){
				printf("%d + %d = %d\n", value, i, (i+value));
			}
			break;


		case 'S':
		case 's':
			printf("Enter your desired value to be subtracted: ");
			scanf("%d", &value);
			printf("\n\n");
			for(i=1; i<=10; i++){
				printf("%d - %d = %value\n", value, i, (i-value));


			}
			break;
		default:
			printf("\nWrong menu item\n");
			break;
		}
		printf("\nContinue [Y/N]? ");
		fflush(stdin);
		scanf("%c", &c);
		
	}while(c !='N' && c !='n');
	printf("\nThank you for choosing my program\n");
	getchar();
	getchar();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS