Tuesday, December 6, 2011

Write a C Program to create CALCULATOR by SWITCH - CASE Operation

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
 int a,b,ch,d,e,i,n;
 float c;
 clrscr();
 printf("\tCalculator Made by SURAJIT SADHUKHAN\n\n\t\t\t\t+-*/%WELCOME%/*-+");
 printf("\n\t 1. Addition\n\t 2. Subtraction\n\t 3. Multiplication\n\t 4. Division\n\t 5. Reminder operation\n\t 6. Squre root\n\t 7. Power operation\n\t 8. Memory Operation.\n\tNow Enter Your Choice: ");
 scanf("%d",&ch);
 printf("\n\tEnter First Number\n\tfor addition, subtraction, multiplication , Division ,reminder operation and squreroot \n\t Number for power operation: ");
 scanf("%d",&a);
 printf("\n\tEnter second number for addition\n\tsubtraction, multiplication, division and reminder operation\n\tpower: ");
 scanf("%d",&b);
 printf("\n\tEntered Choice No=%d",ch);
 switch (ch)
 {
  case 1:
  {
  d=(a+b);
  printf("\n\t Your choice is Addition \n\t your result is: %d",d);
  break;
  }
  case 2:
  {
   d=(a-b);
   printf("\n\t Your choice is Subtraction\n\t Your result is: %",d);
   break;
  }
  case 3:
  {
   d=a*b;
   printf("\n\t Your choice is Multiplication\n\t Your result is: %d",d);
   break;
  }
  case 4:
  {
   c=a/b;
   printf("\n\t Your choice is Divition\n\t Your Result is: %.2f",c);
   break;
  }
  case 5:
  {
   d=a%b;
   printf("\n\t Your Choice is Reminder Operation\n\t Your result is: %d",d);
   break;
  }
  case 6:
  {
   c=sqrt(a);
   printf("\n\tYour choice is root of First Number\n\t Your result is: %.2f",c);
   break;
  }
  case 7:
  {
   d=a^b;
   printf("\n\tYour choice is power calculation \n\t Your result is: %d",d);
   break;
  }
  case 8:
  {
   d=a;
   e=-b;
   printf("\n\tYour choice is Memory operation\n\t Your stored positive number is %d and stored negative number is %d",d,e);
   break;
  }
  default:
  {
   printf("\n\t Your choice is not listed");
  }
 }
 getch();
}

No comments:

Post a Comment