C Program to print smallest of four no by using ternary operators. If you want to find the smallest of four numbers, then you must use a ternary operator to do so. In a ternary operator, you will need to use three variables to store the smallest number.
# include <stdio.h>
# include <conio.h>
main( )
{
int a,b,c,d,small;
clrscr( );
printf(“enter value a”);
scanf(“%d”,&a);
printf(“enter the value of b”);
scanf(“%d”,&b);
printf(“enter the value of c”);
scanf(“%d”,&c);
printf(“enter the value of d”);
scanf(“%d”,&d);
small=(a<b)?(a<c)?(a<d)?a:d:(c<d)?c:d:(b<c)?(b<d)?b:d:(c<d)?c:d;
printf(“biggest of the given 4 numbers IS
%d”,small);
getch();
}
To find the smallest number, first you need to write a simple program. Write a line of code that asks the user to enter a number. The code needs to be able to recognize if the number entered by the user is positive or negative. If it is positive, it should add one to the number entered by the user. However, if the number is negative, it should subtract one from the number entered by the user. After the user has entered a number, the program should output the smallest number.