Welcome to Coding Magazine!

Ad 468 X 60

Saturday, January 26, 2013

Write A Program In C To Create A Simple Arithmetic Calculator ( Using Switch Case )

What is Arithmetic Calculator :-

Arithmetic calculator is one type of calculator in which you can  do some Arithmetic operations between numbers like Addition (+) , Subtraction (-) ,Multiplication (x) and Division (/) .

Program Details :-

This program is a very simple program . in this program i have used one switch case  to carry out all the 

arithmetic operations as individual cases. and another  if statement to display the result.

Complete Program To Create A Simple Arithmetic Calculator

//Source Code By CodingMagazine.blogspot.com
#include<conio.h>
#include<stdio.h>

int main()
 {
  int num1,num2,result=0;
  char choice;
  clrscr();
  printf("\n Enter 1st Number=");
  scanf("%d",&num1);
  printf("\n Enter 2nd Number=");
  scanf("%d",&num2);
  fflush(stdin);
  printf("\n Enter Your Choice (+,-,*,%)=");
  scanf("%c",&choice);

  switch(choice)
   {
    case '+':
     result=num1+num2;
     break;
    case '-':
     result=num1-num2;
     break;
    case '*':
     result=num1*num2;
     break;
    case '%':
     result=num1%num2;
     break;
    default:
     printf("\n Please Enter a Valid Choice");
     break;
 }//Switch Ends

    if(result>0)
       printf("\n Result is=%d",result);

    getch();
    return(0);

}//Main Ends
Any  Help ??
If  You are facing any kind of problem while running the program , then please feel free to ask me by using below comment box (Thanks Also Accepted for successful program execution :) ).

SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
Author: Sarada Prasad
Sarada Prasad is a creative tech writer and tech enthusiastic. He loves to share different programming and tech related articles through this blog. Read More →

If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to our regular Email Updates. Subscribe Now!

0 comments: