Wednesday, July 20, 2011

Program to do basic arithmetic calculation

/*Serial No.62     [swami35.cpp]*/

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a,b,c,ch,num,fact=1,n=0;
char choice='y';
clrscr();
while(choice=='y'||choice=='Y')
  {
  printf("\n:----MENU----:");
  printf("\n[1] :--ADDITION--");
  printf("\n[2] :--SUBSTRACTION--");
  printf("\n[3] :--MULTIPLICATION--");
  printf("\n[4] :--DIVISION--");
  printf("\n[5] :--Factorial--");
  printf("\n[6] :--Exit--");
  printf("\nEnter your choice==>");
  scanf("%d",&ch);
  switch(ch)
    {
    case 1:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a+b;
        printf("\nSUM of %d and %d==%d",a,b,c);
        break;
    case 2:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a-b;
        printf("\nSubstraction of %d and %d==%d",a,b,c);
        break;
    case 3:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a*b;
        printf("\nMultiplication of %d and %d==%d",a,b,c);
        break;
    case 4:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a/b;
        printf("\nDivision of %d and %d==%d",a,b,c);
        break;
    case 5:    printf("\nEnter the number for factorial==>");
        scanf("%d",&num);
        n=num;
        while(n>0)
            {
          fact*=n;
          n=n-1 ;
          }
        printf("\nFactorial of %d is==%d",num,fact);
        break;
    case 6:    exit(0);
    default:    printf("\nWrong Choice");
    }
  printf("\n\nDo you want to continue==>");
  fflush(stdin);
  scanf("%c",&choice);
  }
getch();
}

No comments:

Post a Comment

If you have any doubt, feel free to ask...