Thursday 24 August 2017

Calculator Program using Switch statement in C

Q.Basic Calculator Program Using C Language ?

Ans:

#include <stdio.h>
#include <conio.h>
int main() {
int n,num1,num2,total;
printf("Basic Calculator Program Using C\n\a");
printf("Enter the number 1 for Addition \n");
printf("Enter the number 2 for Subtraction \n");
printf("Enter the number 3 for Multiplication \n");
printf("Enter the number 4 for Division \n");
printf("Please Enter the Number:\n");
scanf("%d",&n);
printf("Enter the First Number:\n");
scanf("%d",&num1);
printf("Enter the Second Number:\n");
scanf("%d",&num2);
switch (n){
case 1:
total=num1+num2;
printf("%d is your value",total);
break;
case 2:
total=num1-num2;
printf("%d is your value",total);
break;
case 3:
total=num1*num2;
printf("%d is your value",total);
break;
case 4:
total=num1/num2;
printf("%d is your value",total);
break;
}

return 0;
}
Result :-

Basic Calculator Program Using 
Enter the number 1 for Addition
Enter the number 2 for Subtraction
Enter the number 3 for Multiplication
Enter the number 4 for Division
Please Enter the Number:
1
Enter the First Number:
140
Enter the Second Number:
3
143 is your value

Graphical Representation :-

Calculator Program using Switch statement in C


No comments:

Post a Comment

Intent in Kotlin Android Studio

 Hi larnkoders in this post you are going to learn  about, How to make pass to new activity with information or simply go to new activity on...