Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to find the max and min from three numbers with short-circuit boolean operators in C

1 Answer

0 votes
#include <stdio.h>

int max_3(int a, int b, int c) {
	int max = a;
	 
	(max < b) && (max = b); 
	 
	(max < c) && (max = c); 
 
	return max;
}
 
int min_3(int a, int b, int c) {
	int min = a;
	 
	(min > b) && (min = b);
	 
	(min > c) && (min = c);
	 
	return min;
}
 
int main()
{
	printf("%d\n", max_3(8, 9, 3));
	printf("%d\n", min_3(9, 7, 4));
	 
	return 0;
}



/*
run:

9
4

*/

 



answered Mar 25, 2019 by avibootz

Related questions

3 answers 292 views
1 answer 235 views
1 answer 222 views
1 answer 146 views
1 answer 210 views
...