Home Forums C Programming calculator programme Reply To: calculator programme

#3263
yeswanth
Participant

#include
#include
#include
main()
{
 int a,b,sum,diff,prdct,ch;
 double sr;
 long sq,cube;
 float c,d,ratio;
 do
  {
    clrscr();
    printf("t*****Ruel Pagayon Copyright--2007--04--10--*****");
    printf("nnntt*****Simple Calculator*****nn");
    printf("tt**Operations**n");
    printf("ttt*(1)Additionn");
    printf("ttt*(2)Subtractionn");
    printf("ttt*(3)Multiplicationn");
    printf("ttt*(4)Divisionn");
    printf("ttt*(5)Squaren");
    printf("ttt*(6)Cuben");
    printf("ttt*(7)SquareRootn");
    printf("nEnter the number of your choice: ");
    scanf("%d", &ch);
    switch(ch)
    {
    case 1:
    printf("nttEnter two numbers: ");
    scanf("%d %d", &a,&b);
    sum = a + b;
    printf("nnttThe Sum is : %d", sum);
    break;
    case 2:
    printf("nttEnter two numbers: ");
    scanf("%d %d", &a,&b);
    diff = a - b;
    printf("nnttThe Difference is : %d", diff);
    break;
    case 3:
    printf("nttEnter two numbers: ");
    scanf("%d %d", &a,&b);
    prdct = a * b;
    printf("nnttThe Product is : %d", prdct);
    break;
    case 4:
    printf("nttEnter two numbers: ");
    scanf("%f %f", &c,&d);
    ratio = c / d;
    printf("nnttThe Quotient is : %f", ratio);
    break;
    case 5:
    printf("nttEnter a number: ");
    scanf("%d", &a);
    sq = a * a;
    printf("nnttThe Square of %d is : %d", a,sq);
    break;
    case 6:
    printf("nttEnter a number: ");
    scanf("%d", &a);
    cube = a * a * a;
    printf("nnttThe Cube of %d is : %d", a,cube);
    break;
    case 7:
    printf("nttEnter a number: ");
    scanf("%d", &a);
    sr = sqrt(a);
    printf("nnttThe SquareRoot of %d is : %f", a,sr);
    break;
    }
  printf("nnnnntttPress 'x' to quit, any other key to continuen");
  }
 while (getch() != 'x');
}