Below is the Program for Multiplying, Dividing, Adding and Subtracting two digits using C++ Programming Language.


# include < stdio.h >
main()
{
int a,b,c,d;
float e,f,g;
char choice;
start:
printf("\t\t\t Select an Operation\n");
printf("\t\t\t 1. Addition\n");
printf("\t\t\t 2. Subtraction\n");
printf("\t\t\t 3. Multiplication\n");
printf("\t\t\t 4. Division\n");
printf("\t\t\t Enter your choice:");
scanf("%d",&a);
switch(a){
    case 1:{
        printf("Enter first digit: ");
        scanf("%d",&b);
        printf("Enter second digit: ");
        scanf("%d",&c);
        d=b+c;
        printf("the sum of %d and %d is %d\n",b,c,d);
        printf("Do you want to try another operaion? (y/n)\n");
        scanf("%s",&choice);
        if(choice=='y')
        goto start;
        break;
          }
    case 2:{
        printf("Enter first digit: ");
        scanf("%d",&b);
        printf("Enter second digit: ");
        scanf("%d",&c);
        d=b-c;
        printf("the difference of %d and %d is %d\n",b,c,d);
        printf("Do you want to try another operaion? (y/n)\n");
        scanf("%s",&choice);
        if(choice=='y')
        goto start;
        break;
          }
    case 3:{
        printf("Enter first digit: ");
        scanf("%d",&b);
        printf("Enter second digit: ");
        scanf("%d",&c);
        d=b*c;
        printf("the product of %d and %d is %d\n",b,c,d);
        printf("Do you want to try another operaion? (y/n)\n");
        scanf("%s",&choice);
        if(choice=='y')
        goto start;
        break;
          }
    case 4:{
        printf("Enter first digit: ");
        scanf("%f",&e);
        printf("Enter second digit: ");
        scanf("%f",&f);
        g=e/f;
        printf("the quotient of %f and %f is %f\n",e,f,g);
        printf("Do you want to try another operaion? (y/n)\n");
        scanf("%s",&choice);
        if(choice=='y')
        goto start;
        break;
          }
    }
}



    In making the program first you must declare the variable used if it is an integer, character, float, etc.
I used the switch function for selecting the operation by choosing from 1 to 5. After selecting an operation,  input the digits you want to execute. The inputted digits will be scan and will be executed to the corresponding operation. If you want to try another operation, you just have to select "y" for yes.

0 comments:

Post a Comment