Tuesday, 9 April 2013

simple program in c using if statement



Two integer operands and one operator form user,   performs the operation and then prints the result.
              (Consider the operators +,-,*, /, % and use Switch Statement)


#include<stdio.h>
main()
{
char op;
float a,b,c;
clrscr();
printf("enter two operands:");
scanf("%d%d",&a,&b);
printf("enter an operator:");
scanf(" %c",&op);
switch(op) // used to select particular case from the user
{
case '+':printf("sum of two numbers %2d %2d is:     %d",a,b,a+b);
                      break;
case '-':printf("subtraction of two numbers %2d %2d is:
                        %d",a,b,a-b);
                      break;
case '*':printf("product of two numbers %2d %2d is:
                       %d",a,b,a*b);
                      break;
         case '/':printf("quotient of two numbers %2d %2d is:
                       %d",a,b,a/b);
                       break;
          case '%':printf("reminder of two numbers %2d %2d is:            
                        %d",a,b,c);
                         break;
           default:printf("please enter correct operator");
                         break;
          }
  getch();
}
12aj1f0001.blogspot.com

No comments: