Advertisement
dmilicev

comparing_4_integers_v1.c

Nov 20th, 2019
228
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None
  1. /*
  2.  
  3.     comparing_4_integers_v1.c       by Dragan Milicev
  4.  
  5.  
  6.     You can find all my C programs at Dragan Milicev's pastebin:
  7.  
  8.     https://pastebin.com/u/dmilicev
  9.  
  10. */
  11.  
  12. #include <stdio.h>
  13.  
  14. int main()
  15. {
  16.     int a=1, b=2, c=3, d=4, max;
  17.  
  18.     // You can compare all this in 4 line (just for comparison)
  19.  
  20.     max = a;
  21.     max = (b>max) ? b : max;
  22.     max = (c>max) ? c : max;
  23.     max = (d>max) ? d : max;
  24.  
  25.     printf("\n a = %d \t b = %d \t c = %d \t d = %d \t max = %d  \n", a, b, c, d, max );
  26.  
  27.     // or,to me it is more understandable:
  28.  
  29.     max = a;
  30.     if ( b>max ) max=b;
  31.     if ( c>max ) max=c;
  32.     if ( d>max ) max=d;
  33.  
  34.     printf("\n a = %d \t b = %d \t c = %d \t d = %d \t max = %d  \n", a, b, c, d, max );
  35.  
  36.     return 0;
  37. }
Advertisement
RAW Paste Data Copied
Advertisement