c programming conditional operators

We already discussed c programming conditional operators with various expressions in our earlier tutorial lets see few examples

C program to find the minimum value of 3 variable

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/* simple example to find min value of 3 variable */
#include <stdio.h>
int main()
{
int x,y,z,min;
x=10; y=5; z=20;
min = x<y&&x<z ? x : y<z ? y : z ;
printf("Min value is:%d",min);
return 0;
}
/* simple example to find min value of 3 variable */ #include <stdio.h> int main() { int x,y,z,min; x=10; y=5; z=20; min = x<y&&x<z ? x : y<z ? y : z ; printf("Min value is:%d",min); return 0; }
/* simple example to find min value of 3 variable */ 
#include <stdio.h> 
int main() 
{ 
    int x,y,z,min; 
    x=10; y=5; z=20; 
    min = x<y&&x<z ? x : y<z ? y : z ; 
    printf("Min value is:%d",min); 

    return 0; 
}

Output: [quote]Min value is:5 [/quote] 

C program to find the maximum value of 4 input values

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/* complex example to find max value of 4 variable */
#include <stdio.h>
int main()
{
int a,b,c,d,max;
printf("Enter 4 values: ");
scanf("%d%d%d%d",&a,&b,&c,&d);
max = a>b&&a>c&&a>d ? a:b>c&&b>d ? b:c>d ? c : d;
printf("Max value is:%d",max);
return 0;
}
/* complex example to find max value of 4 variable */ #include <stdio.h> int main() { int a,b,c,d,max; printf("Enter 4 values: "); scanf("%d%d%d%d",&a,&b,&c,&d); max = a>b&&a>c&&a>d ? a:b>c&&b>d ? b:c>d ? c : d; printf("Max value is:%d",max); return 0; }
/* complex example to find max value of 4 variable */ 
#include <stdio.h> 
int main() 
{ 
    int a,b,c,d,max; 
    printf("Enter 4 values: "); 
    scanf("%d%d%d%d",&a,&b,&c,&d); 
    max = a>b&&a>c&&a>d ? a:b>c&&b>d ? b:c>d ? c : d; 
    printf("Max value is:%d",max);
    
    return 0; 
}

Output:

[quote]

Enter 4 values: 10 30 40 20                                                                                                                                  
Max value is:40 

[/quote]

[review]

Leave a Reply

Your email address will not be published. Required fields are marked *