Define control structure. Write a C program to find the sum, difference and greater of two integer numbers using switch case statement.

Solution: 
Control structures are fundamental building blocks of programming and allow programs to make decisions and repeat actions based on various conditions. By using control structures, programs can be made more efficient, flexible, and powerful.

Program:

#include <stdio.h>

int main() {
    int num1, num2, choice, sum, diff, greater;
    
    printf("Enter two integer numbers: ");
    scanf("%d %d", &num1, &num2);
    
    printf("Choose an operation:\n");
    printf("1. Sum\n");
    printf("2. Difference\n");
    printf("3. Greater\n");
    scanf("%d", &choice);
    
    switch(choice) {
        case 1:
            sum = num1 + num2;
            printf("Sum: %d\n", sum);
            break;
        case 2:
            diff = num1 - num2;
            printf("Difference: %d\n", diff);
            break;
        case 3:
            greater = (num1 > num2) ? num1 : num2;
            printf("Greater: %d\n", greater);
            break;
        default:
            printf("Invalid choice\n");
            break;
    }
    
    return 0;
}

Getting Info...

Post a Comment

Please do not enter any spam link in the comment box.
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.