Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

simple calculator, using switch statement in C

#include<stdio.h>
#include<conio.h>
void main()
{
	int num1,num2,opt;
	clrscr();
	printf("Enter the first Integer:
");
	scanf("%d",&num1);
	printf("Enter the second Integer:
");
	scanf("%d",&num2);
	for(;;)
	{
		printf("



Enter the your option:
");
		printf("1-Addition.
2-Substraction.
3-Multiplication.
4-Division.
5-Exit.
");
		scanf("%d",&opt);
		switch(opt)
		{
			case 1:printf("
Addition of  %d and %d is: %d",num1,num2,num1+num2);
			break;
			case 2:printf("
Substraction of %d  and %d is:  %d",num1,num2,num1-num2);
			break;
			case 3:printf("
Multiplication of %d  and %d is:  %d",num1,num2,num1*num2);
			break;  
			case 4: 
			if(num2==0)
			{
				printf("OOps Devide by zero
");
			}
			else
			{
				printf("
 Division of %d  and %d is:  %d",num1,num2,num1/num2);
			}  
			break;
			case 5: return 0;
			break; 
			default:printf("
 Enter correct option
");
			break; 
		}
	}
	getch();
}
Source by scanftree.com #
 
PREVIOUS NEXT
Tagged: #simple #switch #statement #C
ADD COMMENT
Topic
Name
8+8 =