Biggest of four Nos using Macro..

Discussion in 'C' started by Nageshha, Oct 19, 2005.

  1. Nageshha

    Nageshha New Member

    Joined:
    Oct 18, 2005
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #define f(a,b,c,d) (a>b?(a>c?(a>d?a:d):(c>d?c:d)):(b>c?(b>d?b:d):(c>d?c:d)))
    
    #include<stdio.h>
    #include<conio.h>
    
    void main()
    {
    	int a, b, c, d, k;
    	clrscr();
    	printf("Enter the value of a, b, c, d\n");
    	scanf("%d%d%d%d", &a, &b, &c, &d);
    	printf("\n%d\n", f(a, b, c, d));
    	getch();
    }
     
  2. Nageshha

    Nageshha New Member

    Joined:
    Oct 18, 2005
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    hey guys ':' followed by '(' is acting as sad smiley so pls whereever u se smiley replace it by ':' follwed by '(' ...

    Thanks
    Nagesh
     
    Last edited: Oct 19, 2005
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I have edited that for no smiley as well as proper formating. Here is the code snippet again for you

    Code:
    #define f(a,b,c,d) (a>b?(a>c?(a>d?a:d):(c>d?c:d)):(b>c?(b>d?b:d):(c>d?c:d)))
    
    #include<stdio.h>
    #include<conio.h>
    
    void main()
    {
           int a, b, c, d, k;
           clrscr();
           printf("Enter the value of a, b, c, d\n");
           scanf("%d%d%d%d", &a, &b, &c, &d);
           printf("\n%d\n", f(a, b, c, d));
           getch();
    }
     
  4. Nageshha

    Nageshha New Member

    Joined:
    Oct 18, 2005
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    thanks shabbir..
     
  5. imrantechi

    imrantechi New Member

    Joined:
    Feb 12, 2008
    Messages:
    116
    Likes Received:
    4
    Trophy Points:
    0
  6. sydneytech

    sydneytech New Member

    Joined:
    Feb 6, 2008
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Can you make it generic for any number ( not only for four).
     
  7. sydneytech

    sydneytech New Member

    Joined:
    Feb 6, 2008
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Just try and you can do taking a sort of template not exactly template.

    Because i need this requirement...
     
  8. heena.mca

    heena.mca New Member

    Joined:
    Feb 14, 2008
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Very good info for me.
     
  9. lead.smart34

    lead.smart34 New Member

    Joined:
    Feb 14, 2008
    Messages:
    77
    Likes Received:
    0
    Trophy Points:
    0
  10. crazytolearn57

    crazytolearn57 New Member

    Joined:
    Feb 14, 2008
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    0
  11. aisha.ansari84

    aisha.ansari84 New Member

    Joined:
    Feb 13, 2008
    Messages:
    82
    Likes Received:
    1
    Trophy Points:
    0

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice