Sunday, September 16, 2012

program to perform basic arithmetic operations

/*program to perform basic arithmetic operations*/

#include<stdio.h>
#include<conio.h>           
void main()
{
float a,b,s;
char ch;
clrscr();
printf("+addition\n-subtraction\n*multiplication\n/.divition\n");
do
{
printf("\nchoose the right option\n");
scanf("%c",&ch);
switch(ch)
{
case '+':printf("Enter the values\n") ;
      scanf("%f%f",&a,&b);
      s=a+b;
      printf("the value is \t%f",s);
      break;

case '-':printf("Enter the values\n");
      scanf("%f%f",&a,&b);
      s=a-b;
      printf("the value is \t%f",s);
      break;

case '*':printf("Enter the values\n");
      scanf("%f%f",&a,&b);
      s=a*b;
      printf("the value is \t%f",s);
      break;

case '/':printf("Enter the values\n");
      scanf("%f%f",&a,&b);
      s=a/b;
      printf("the value is \t%f",s);
      break;

default : printf("sorry choose the right one\n");
}
printf("\n\nDo you want to continue(y/n)\n");
scanf("%s",&ch);
}while((ch=='y')||(ch=='Y'));

 getch();

 }
This program takes operators as input at first time.Then it reads operand .According to the corresponding operators and operands it produces the output

No comments:

Post a Comment