Search Here

C program for menu driven arithmetic operations



/* C program for Menu Driven Arithmetic Program */

void main()
{
    int ch;
    float x,y;
    
    printf("\n\tMenu driven Arithmetic Program");
    printf("\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Division");
    printf("\nEnter your choice: ");
    scanf("%d",&ch);
    printf("\nEnter two numbers: ");
    scanf("%f%f",&x,&y);
    switch(ch)
    {
        case 1: printf("\nResult of addition is %f",x+y);
                break;
        case 2: printf("\nResult of subtraction is %f",x-y);
                break;
        case 3: printf("\nResult of addition is %f",x*y);
                break;
        case 4: if(y!=0)
                    printf("\nResult of division is %f",x/y);
                else
                    printf("\nInvalid operation");
        default: printf("Invalid choice!");
    }
}


Output


No comments:

Post a Comment