Computer Science, asked by mohapatratanushree34, 6 months ago

Write a program to find Minimum of 2 nos. using conditional operator.

Answers

Answered by REDPLANET
20

Answer:

This is a C program.

#include<stdio.h>

#include<conio.h>

void main()

{

 int a,b;

 clrscr();

 printf("\n Enter any Two numbers\n");

 printf("\n Enter First Number : ");

 scanf("%d",&a);

 printf("\n Enter Second Number : ");

 scanf("%d",&b);

 if(a<b)   //logical test

  {

   printf("\n %d is Smaller",a);

  }

 else

  {

   printf("\n %d is Smaller",b);

  }

getch();

}

Answered by AneesKakar
0

Here is a program in C language to find a Minimum of 2 numbers using a conditional operator:

#include <stdio.h>

int main() {

   float num1, num2, min_num;

   

   printf("Enter the first number: ");

   scanf("%f", &num1);

   

   printf("Enter the second number: ");

   scanf("%f", &num2);

   

   min_num = (num1 < num2) ? num1 : num2;

   

   printf("The minimum number is: %f", min_num);

   

   return 0;

}

In the above program, firstly three variables are declared - num1, num2, and min_num - all of the type float. The printf() function is used to prompt the user to enter the two numbers, and the scanf() function reads the input values and stores them in num1 and num2 variables, respectively.

Next, the conditional operator (num1 < num2) ? num1 : num2 is used to compare the two numbers. If num1 is less than num2, it returns num1, otherwise it returns num2. This result is then assigned to the min_num variable.

Finally, the printf() function displays the minimum number.

#SPJ3

Similar questions