C Language Tutorials by Ghulam Murtaza Dahar - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

corresponding calculation on the operands.

/* C program to demonstrate the working of switch...case statement */

/* Program to create a simple calculator for addition, subtraction, multiplication and

division */

# include <stdio.h>

int main(){

char operator;

float num1,num2;

printf("Enter operator +, - , * or / :\n");

operator=getche();

printf("\nEnter two operands:\n");

scanf("%f%f",&num1,&num2);

switch(operator)

{

case '+':

printf("num1+num2=%.2f",num1+num2);

break;

case '-':

printf("num1-num2=%.2f",num1-num2);

break;

case '*':

printf("num1*num2=%.2f",num1*num2);

break;

case '/':

printf("num2/num1=%.2f",num1/num2);

index-34_1.jpg

break;

default:

/* if operator is other than +, -, * or /, error message is shown */

printf(Error! operator is not correct");

break;

}

return 0;

}

Find Your Next Great Read

Describe what you're looking for in as much detail as you'd like.
Our AI reads your request and finds the best matching books for you.

Showing results for ""

Popular searches:

Romance Mystery & Thriller Self-Help Sci-Fi Business