Dremendo Tag Line

Divide larger number with smaller number in C

if else if - Question 5

In this question, we will see how to input 2 integers and divide the larger number with the smaller one and display the result in C programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.

Q5) Write a program in C to input 2 integers. If either of the two number is 0, display Invalid input, if it is valid entry, divide the larger number with the smaller number and display the result.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int a,b;
    printf("Enter 2 numbers\n");
    scanf("%d%d",&a,&b);
    if(a==0 || b==0)
    {
        printf("Invalid input");
    }
    else if(a>b)
    {
        printf("Result of division = %f",a/(float)b);
    }
    else if(b>a)
    {
        printf("Result of division = %f",b/(float)a);
    }
    return 0;
}

Output

Enter 2 numbers
5
2
Result of division = 2.500000
video-poster