wisdomatrix.com

Avatar

C Program to Making a Simple Calculator Using Switch Case

In C programming, the switch statement is a control flow statement that provides a way to handle multiple cases based on the value of an expression. It is commonly used when you have a variable or an expression and you want to execute different code blocks based on its value. The basic syntax of the switch statement is as follows: Syntax : switch (expression) { case constant1: // code to be executed if expression matches constant1 break; case constant2: // code to be executed if expression matches constant2 break; // additional cases as needed default: // code to be executed if none of the cases match } Switch-case Calculator A switch-case statement in C is often used to implement a simple calculator program. In this example, I’ll show you how to create a basic calculator that performs addition, subtraction, multiplication, and division based on user input. Program : #include<stdio.h>#include<conio.h>int main(){float a,b;char op;printf(“Enter First Number = “);scanf(“%f”,&a);printf(“Enter Second Number = “);scanf(“%f”,&b);printf(“Enter any Operator = “);scanf(“%s”,&op);switch(op) {case ‘+’: printf(“You Select Sum : \n Sum of Two Numbers is = “);printf(“%0.3f + %0.3f = %0.3f”,a,b,a+b);break;case ‘-‘: printf(“You Select Subtraction : \n Subtraction of Two Numbers is = “);printf(“%0.3f – %0.3f = %0.3f”,a,b,a-b);break;case ‘*’: printf(“You Select Multiplication : \n Multiplication of Two Numbers is = “);printf(“%0.3f * %0.3f = %0.3f”,a,b,a*b);break;case ‘/’: printf(“You Select Division : \n Division of Two Numbers is = “);printf(“%0.3f / %0.3f = %0.3f”,a,b,a/b);break;default : printf(“\nWrong Input!”);}return 0;} Output :

C Program to Making a Simple Calculator Using Switch Case Read More »

C Program to Division Between Two Numbers

In C programming, division is an arithmetic operation that involves dividing one number by another. The division operator in C program is represented by the forward slash (“/”). The basic syntax for division in C is: Interger Numbers : #include<stdio.h>#include<conio.h>main(){int a,b,c;printf(“Enter first Number = “);scanf(“%d”,&a);printf(“Enter Second Number = “);scanf(“%d”,&b);c=a/b;printf(“Division of two numbers is = %d”,c);} Output : Float Numbers : #include<stdio.h>#include<conio.h>main(){float a,b,c;printf(“Enter first Number = “);scanf(“%f”,&a);printf(“Enter Second Number = “);scanf(“%f”,&b);c=a/b;printf(“Division of two numbers is = %f”,c);} Output :

C Program to Division Between Two Numbers Read More »

C Program to Multiplication of Two Numbers

In a C program, multiplication is an arithmetic operation that involves multiplying two or more values to obtain their product. The multiplication operator in C is the asterisk symbol (*). Here’s a basic example: Interger Numbers : #include<stdio.h>#include<conio.h>main(){int a,b,c;printf(“Enter first Number = “);scanf(“%d”,&a);printf(“Enter Second Number = “);scanf(“%d”,&b);c=a*b;printf(“Multiplication of two numbers is = %d”,c);} Output : Float Numbers : #include<stdio.h>#include<conio.h>main(){float a,b,c;printf(“Enter first Number = “);scanf(“%f”,&a);printf(“Enter Second Number = “);scanf(“%f”,&b);c=a*b;printf(“Multiplication of two numbers is = %f”,c);} Output :

C Program to Multiplication of Two Numbers Read More »

C Program to Subtraction of Two Numbers

C Program to Subtraction of Two Numbers Subtraction in a C program is performed using the subtraction operator (-). The subtraction operator subtracts the value on the right-hand side of the operator from the value on the left-hand side. Here’s a simple example: Interger Numbers : #include<stdio.h>#include<conio.h>main(){int a,b,c;printf(“Enter first Number = “);scanf(“%d”,&a);printf(“Enter Second Number = “);scanf(“%d”,&b);c=a-b;printf(“Subtraction of two numbers is = %d”,c);} Output : Float Numbers : #include<stdio.h>#include<conio.h>main(){float a,b,c;printf(“Enter first Number = “);scanf(“%f”,&a);printf(“Enter Second Number = “);scanf(“%f”,&b);c=a-b;printf(“Subtraction of two numbers is = %0.2f”,c);} Output :

C Program to Subtraction of Two Numbers Read More »

C Program to Additon of Two Numbers

C Program to Additon of Two Numbers In the C program, addition is a basic arithmetic operation performed using the ‘+‘ operator. The ‘+‘ operator adds two numeric values together. Here’s a simple example: Interger Numbers : #include<stdio.h>#include<conio.h>main(){int a,b,c;printf(“Enter first Number = “);scanf(“%d”,&a);printf(“Enter Second Number = “);scanf(“%d”,&b);c=a+b;printf(“Sum of two numbers is = %d”,c);} Output : Float Numbers : #include<stdio.h>#include<conio.h>main(){float a,b,c;printf(“Enter first Number = “);scanf(“%f”,&a);printf(“Enter Second Number = “);scanf(“%f”,&b);c=a+b;printf(“Sum of two numbers is = %0.2f”,c);} Output :

C Program to Additon of Two Numbers Read More »

Shopping Basket
Verified by MonsterInsights