Download Big Number Calculator C C+ C++
Estimator Plan in C | Simple Estimator Program in C
Today we will learn how to make a Unproblematic Calculator program in C and also learn Calculator program in C using switch example, functions and else if statements. So before starting, nosotros volition take an overview of the functioning of figurer.
How Computer Works?
Afterwards executing the program the compiler asks the user to enter the sign like '+' for improver,'-' for subtraction,'*' for multiplication,'/' for the division. When the user input sign then using switch statement compiler finds for that instance functioning in the program.
When the compiler finds that instance compiler starts executing and so ask the user to input two numbers so that the plan tin can do operation on that ii numbers.
And finally, compiler prints the output on the screen.
Figurer Programme in C Algorithm
1 Step: BEGIN.
ii Step: PRINT ENTER YOUR CHOICE.
3 Pace: ENTER YOUR Choice.
4 Step: ENTER Two OPERANDS FOR OPERATION.
v Pace: USER WILL ENTER +,-,*,/ .
6 Step: SWITCH(OPERATOR)
7 Pace: DO THE Performance.
viii Footstep: PRINT THE Issue.
8 Stride: Get out.
At that place are dissimilar methods to write a Calculator program in C we will see those program's ane by one.
one. Calculator Program in C Using Switch Case
In this program, we volition inquire the user to input the operation sign and the program will start doing operation and will print the output on the screen.
#include<stdio.h> int master() { int choice; long num1, num2, x; printf("Please cull your option:" "\n1 = Addition" "\n2 = Subtraction" "\n3 = Multiplication" "\n4 = Division" "\n5 = Squares" "\n6 = exit" "\n\nChoice: "); scanf("%d", &choice); //while loop cheque whether the choice is in the given range while(option < ane || choice > 6) { printf("\nPlease choose the above mentioned option." "\nChoice: "); scanf("%d", &option); } switch (choice) { case one: printf("Enter 2 numbers: \n"); scanf("%ld %ld", &num1, &num2); x = num1 + num2; printf("Sum = %ld", x); break; example 2: printf("Enter two numbers: \n"); scanf("%ld %ld", &num1, &num2); x = num1 - num2; printf("Subtraction = %ld", x); suspension; example iii: printf("Enter ii numbers: \n"); scanf("%ld %ld", &num1, &num2); x = num1 * num2; printf("Product = %ld", x); break; case 4: printf("Enter Dividend: "); scanf("%d", &num1); printf("Enter Divisor: "); scanf("%d", &num2); //while loop checks for divisor whether it is aught or not while(num2 == 0) { printf("\nDivisor cannot exist zero." "\nEnter divisor one time once again: "); scanf("%d", &num2); } x = num1 / num2; printf("\nQuotient = %ld", x); suspension; case 5: printf("Enter any number: \northward"); scanf("%ld", &num1); x = num1 * num1; printf("Foursquare = %ld", x); break; case 6: return; default: printf("\nError"); } } Output:
In the above 1 output Add-on operation is washed because of user input 1 for addition. In 2nd output multiplication is done because of input 3 for functioning.
ii. Directly doing Performance in Case Statement
This program is the same every bit the above plan but we will practice operation straight in the case argument. Only, the logic behind the program is the same.
#include <stdio.h> int main() { char Operator; bladder num1, num2, result = 0; printf("\due north Please Enter an Operator (+, -, *, /) : "); scanf("%c", &Operator); printf("\n Please Enter the Values for two Operands: num1 and num2 : "); scanf("%f%f", &num1, &num2); switch(Operator) { case '+': printf("\n The consequence of %.2f + %.2f = %.2f", num1, num2, num1 + num2); break; instance '-': printf("\n The result of %.2f - %.2f = %.2f", num1, num2, num1 - num2); suspension; instance '*': printf("\northward The result of %.2f * %.2f = %.2f", num1, num2, num1 * num2); break; case '/': printf("\north The result of %.2f / %.2f = %.2f", num1, num2, num1 / num2); break; default: printf("\n You have enetered an Invalid Operator "); } return 0; } Output:
In the above program, the compiler is asking the user to enter the arithmetics operators such as +,-,*,/ and also inquire to input two numbers so the operations tin be done using two numbers.
3. Uncomplicated Reckoner Program in C Using if-else Statement
In this program, we volition use else if argument instead of switch case statement.
#include <stdio.h> int main() { char Operator; float num1, num2, result = 0; printf("\n Please Enter an Operator (+, -, *, /) : "); scanf("%c", &Operator); printf("\n Please Enter the Values for two Operands: num1 and num2 : "); scanf("%f%f", &num1, &num2); if(Operator == '+') { printf("\due north The event of %.2f + %.2f = %.2f", num1, num2, num1 + num2); } else if(Operator == '-') { printf("\n The effect of %.2f - %.2f = %.2f", num1, num2, num1 - num2); } else if(Operator == '*') { printf("\due north The outcome of %.2f * %.2f = %.2f", num1, num2, num1 * num2); } else if(Operator == '/') { printf("\north The result of %.2f / %.2f = %.2f", num1, num2, num1 / num2); } else { printf("\n Yous have enetered an Invalid Operator "); } return 0; } Output:
4. Calculator Program in C Using Function
In this plan, we have alleged user-defined functions.
#include<stdio.h> #include<stdlib.h> //function declarations void display(float n1, float n2, char ch, float result); void add(float n1, float n2); void decrease(float n1, bladder n2); void multiply(float n1, float n2); void split(float n1, float n2); void rem(bladder n1, bladder n2); void power(float n1, bladder n2); //main function int chief() { bladder n1, n2; int ch; do{ printf("Enter two numbers: "); scanf("%f %f", &n1, &n2); printf("\north*****************"); printf("\n1.Addition"); printf("\n2.Subtraction"); printf("\n3.Multiplication"); printf("\n4.Partitioning"); printf("\n5.Remainder"); printf("\n6.Ability (x^y)"); printf("\n7.Get out"); printf("\nEnter your choice: "); scanf("%d", &ch); switch (ch) { example ane: add(n1,n2); break; case 2: subtract(n1,n2); break; example 3: multiply(n1,n2); break; case iv: carve up(n1,n2); break; example 5: rem(n1,n2); intermission; case 6: power(n1,n2); interruption; case 7: printf("Give thanks You."); get out(0); default: printf("Invalid input."); printf("Please enter correct input."); } printf("\northward**********************************\northward"); }while(1); return 0; } //office for displaying the result void display(bladder n1, bladder n2, char ch, float effect) { printf("%.2f %c %.2f = %.2f\n", n1, ch, n2, result); } //function for improver of ii numbers void add(float n1, float n2) { bladder issue = n1 + n2; display(n1, n2, '+', result); } //function for subtraction of two numbers void subtract(bladder n1, float n2) { bladder result = n1 - n2; display(n1, n2, '-', event); } //function for multiplication of two numbers void multiply(float n1, float n2) { float result = n1 * n2; display(n1, n2, '*', event); } //function for sectionalization of 2 numbers void divide(float n1, float n2) { float result = n1 / n2; display(n1, n2, '/', result); } //function for calculating remainder void rem(float n1, float n2) { //Modulus operator only works on int information type //Floating numbers are converted to int number int num1 = n1; int num2 = n2; int effect = num1%num2; printf("%d %% %d = %d\n", num1, num2, result); } //function for calculating power void power(float n1, float n2) { if(n2<0) printf("2d number should be +ve."); else { float result=ane.0; for(int i=1; i<=n2; i++) { event *= n1; } display(n1, n2, '^', issue); } } Besides Read:
- C Plan to print Prime number Numbers from 1 to due north
- Armstrong Number Program in C
- Fibonacci Series Programme in C
- Decimal to Binary Conversion Program in C
- Opposite a String in C
- Program to Contrary a Number in C
- How-do-you-do World Program in C
- Palindrome Programme in C
- Leap Year Program in C
- Factorial Programme in C
- Prime Number Program in C
DOWNLOAD HERE
Posted by: merrittandessomeho.blogspot.com

0 Komentar
Post a Comment