Wednesday 2 August 2017

code for making calculator for fractions

#include"stdio.h"
#include"conio.h"
float a,b,c,d,r;
char op;
void main()
{
    printf("Enter the 1st fraction and 2nd fraction\n");
    scanf("%f",&a); printf("/"); scanf("%f",&b); scanf("%f",&c); printf("/"); scanf("%f",&d);
    printf("Enter the opreter\n");
    op=getche();
    printf("\n");
    while(op!='0')
    {
       
      switch(op)
       {
         case'+':
        {
            r=(a*d+b*c)/(b*d);
            printf("Result is %f\n",r);
            break;
        }
        case'-':
        {
            r=(a*d-b*c)/(b*d);
            printf("Result is %f\n",r);
            break;
        }
        case'*':
        {
            r=(a*c)/(b*d);
            printf("Result is %f\n",r);
            break;
        }
        case'/':
        {
            r=(a*d)/(b*c);
            printf("Result is %f\n",r);
            break;
        }
    }
   
    printf("Enter the 1st fraction and 2nd fraction\n");
    scanf("%f",&a); printf("/"); scanf("%f",&b); scanf("%f",&c); printf("/"); scanf("%f",&d);
    printf("Enter the opreter\n");
    op=getche();
    printf("\n");
    }
        getch();
}

   

0 comments: