The Artima Developer Community
Sponsored Link

Java Buzz Forum
C program for addition subtraction multiplication and division using switch case

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
C program for addition subtraction multiplication and division using switch case Posted: Jun 10, 2017 5:11 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: C program for addition subtraction multiplication and division using switch case
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
  • Write a C program to simulate a simple calculator to perform arithmetic operations like a and division only on integers. Error message should be reported if any attempt is made to divide by zero    
  • C program for addition subtraction multiplication and division using switch case
  • Write a c program to perform arithmetic operations using switch case
  • C program to add subtract multiply and divide two numbers using functions
Program #1: Write a c program to perform arithmetic operations using switch case



  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. int main()
  5. {
  6.     char oper;            /* oper is an operator to be selected */
  7.     float n1, n2, result;
  8.  
  9.     printf ("Simulation of a Simple Calculator\n\n");
  10.  
  11.     printf("Enter two numbers\n");
  12.     scanf ("%f %f", &n1, &n2);
  13.  
  14.     fflush (stdin);
  15.  
  16.     printf("Enter the operator [+,-,*,/]\n");
  17.     scanf ("%c", &oper);
  18.  
  19.     switch (oper)
  20.        {
  21.         case '+': result = n1 + n2;
  22.               break;
  23.         case '-': result = n1 - n2;
  24.               break;
  25.         case '*': result = n1 * n2;
  26.               break;
  27.         case '/': result = n1 / n2;
  28.               break;
  29.         default : printf ("Error in operation\n");
  30.               break;
  31.     }
  32.  
  33.     printf ("\n%5.2f %c %5.2f= %5.2f\n", n1,oper, n2, result);
  34. getch();
  35. }


Output:

algorithm for switch case in c


  • Output
    Simulation of Simple Calculator

    Enter two numbers
    3 5
    Enter the operator [+,-,*,/]
    +

     3.00 +  5.00=  8.00
     
  • RUN2
    Simulation of Simple Calculator

    Enter two numbers
    12.75
    8.45
    Enter the operator [+,-,*,/]
    -

    12.75 -  8.45=  4.30
  • RUN3
    Simulation of Simple Calculator

    Enter two numbers
    12 12
    Enter the operator [+,-,*,/]
    *

    12.00 * 12.00= 144.00
     
  • RUN4
    Simulation of Simple Calculator

    Enter two numbers
    5
    9
    Enter the operator [+,-,*,/]
    /

     5.00 /  9.00=  0.56

Read: C program for addition subtraction multiplication and division using switch case

Topic: Print semicolon without using semicolon in java Previous Topic   Next Topic Topic: Use Precise Java Method Parameters

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use