Search
 
SCRIPT & CODE EXAMPLE
 

C

Calculator in c

#include <stdio.h>
#include <math.h>
#include <string.h>

int main()
{   
    char answer[10];
    char dump;
    printf("Welcome To Cli Calculator
Made by Argha Datta
");
    
    do
    {
        char inputUser;
        float num1, num2, result;
        printf("Please enter your state of operation: ");
        scanf("%c",&inputUser);
    
        printf("Enter the first operand: ");
        scanf("%f",&num1);
        printf("Enter the second operand: ");
        scanf("%f",&num2);
        switch (inputUser)
        {
        case '+':
            printf("The Addition of %f and %f is %f
",num1,num2,num1+num2);
            break;
        case '-':
            printf("The Subtraction of %f and %f is %f
",num1,num2,num1-num2);
            break;
        case '*':
            printf("The Multiplication of %f and %f is %f
",num1,num2,num1*num2);
            break;
        case '/':
            printf("The Division of %f and %f is %f
",num1,num2,num1/num2);
            break;
        case '^':
            printf("The Result of %f ^ %f is %f
",num1,num2,powf(num1,num2));
        default:
            printf("Invalid Operation,please try again!
");
            break;
        }
        printf("Do you want to run it again(if yes ,type yes or type no for exit) :");
        scanf("%s",answer);
        dump = getchar();

    } while (strcmp(answer,"yes")  == 0);
    
    return 0;
}
Comment

Calculator in C

#include<stdio.h>
#include<conio.h>

void main()
{
char choice;
int a,b,res=0;
clrscr();
printf("Enter First value: ");
scanf("%d",&a);
printf("
 Enter Operator: ");
choice=getch();
printf("
 Enter Second value: ");
scanf("%d",&b);

switch(choice)
{
case '+':
  res=a+b;
  printf("Sum: %d",res);
break;
case '-':
  res=a-b;
  printf("Difference: %d",res);
break;
case '*':
  res=a*b;
  printf("Product: %d",res);
break;
case '/':
  res=a/b;
  printf("Quotient: %d",res);
break;
default:
  printf("Enter Valid Operator!!");
}
getch();
}
Comment

PREVIOUS NEXT
Code Example
C :: arduino digital input pins 
C :: successeur d’un entier donné 
C :: printf c float 
C :: how to find sum of two nums 
C :: input in c 
C :: array loop in c 
C :: c Program for Sum of the digits of a given number 
C :: exclamation mark in c 
C :: servo motor arduino 
C :: what is covert channel 
C :: read from a file c 
C :: get range of values in mongodb 
C :: c programing strtok use 
C :: c program for swapping of two numbers using temporary variable 
C :: goto statement in c 
C :: callback c++ c 
C :: how to read keyboard input in C 
C :: fopen in c example 
C :: number of hours, minutes, and seconds given the number of seconds. 
C :: c header file example 
C :: typedef vs #define 
C :: quick sort c 
C :: converting strings to numbers in c 
C :: pop and push shows black screen which needs to be pressed back flutter 
C :: 2d array in c 
C :: sleep in c 
C :: notation of positive in c 
C :: script in c 
C :: C Syntax of realloc() 
C :: arduino dont working dc motor 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =