C Program for Basic Arithmetic Operations, Assignments of Computer science

This c program allows users to perform addition, subtraction, multiplication, division, and modulus operations by inputting their choice and two numbers.

Typology: Assignments

2019/2020

Uploaded on 04/17/2020

t_raghava
t_raghava 🇮🇳

1 document

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1 #include <stdio.h>
2
3 int main()
4 {
5 char ch;
6 int a,b;
7
8 printf("Add\nSub\nMul\nDiv\nmOd\nEnter your choice:");
9 ch =getchar();
10
11 printf("Enter the two numbers :");
12 scanf("%d%d",&a,&b);
13
14 switch(ch){
15 case 'A':
16 case 'a':
17 printf("Sum = %d\n",a+b);
18 break;
19 case 'S':
20 case 's':
21 printf("Dif = %d\n",a-b);
22 break;
23 case 'M':
24 case 'm':
25 printf("Pro = %d\n",a*b);
26 break;
27 case 'D':
28 case 'd':
29 printf("Quo = %d\n",a/b);
30 break;
31 case 'O':
32 case 'o':
33 printf("Rem = %d\n",a%b);
34 break;
35 default:
36 printf("Please choose a valid option\n");
37 }
38
39 }
40

Partial preview of the text

Download C Program for Basic Arithmetic Operations and more Assignments Computer science in PDF only on Docsity!

1 #include <stdio.h> 2 3 int main() 4 { 5 char ch; 6 int a,b; 7 8 printf("Add\nSub\nMul\nDiv\nmOd\nEnter your choice:"); 9 ch = getchar(); 10 11 printf("Enter the two numbers :"); 12 scanf("%d%d",&a,&b); 13 14 switch(ch){ 15 case 'A': 16 case 'a': 17 printf("Sum = %d\n",a+b); 18 break; 19 case 'S': 20 case 's': 21 printf("Dif = %d\n",a-b); 22 break; 23 case 'M': 24 case 'm': 25 printf("Pro = %d\n",a*b); 26 break; 27 case 'D': 28 case 'd': 29 printf("Quo = %d\n",a/b); 30 break; 31 case 'O': 32 case 'o': 33 printf("Rem = %d\n",a%b); 34 break; 35 default: 36 printf("Please choose a valid option\n"); 37 } 38 39 } 40