Thread: Array programme help

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    46

    Smile Array programme help

    Hello Everyone,

    How can i write a programme in c which finds the biggest integer in the array without using any loop.........

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    use recursion

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by baccardi View Post
    use recursion
    Assuming you count that as a loop - of course, anything else is an impossible task, but that's a different matter.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    well i thought he ment loop as a syntax concept, but i agree with you, its impossible to compare the elements of array without a loop

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    46
    Thank You for your reply........

  6. #6
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    No. A whole whack of nested ifs should do... as long as you know the size of the array and it's fixed.

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    2

    Wink reply for biggest

    Code:
     {
        
       int i=1, L, big;
        //find length  of arrray in any int variable.
    //then
    //if u dont want to use recursive()  , use goto statement 
      
      //do this
    big= array[0];
    
      lable:
        if(L<len)  //len is length of  array
       {
           if(big<array[i])       
               big=array[i];
               
         i++, L++;
         goto lable;
      }     
                
       //use printf here with big variable           
    
    getch();
    }
    
    
    //try it , i haven' t tried yet.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    A couple of advices for you. Here is probably what you should fix in your code:
    1) Indentation is lacking.
    2) Use of goto should be gotten rid of (use loops).

    Also:
    It's bad to hand out solutions to people, because often they will learn much more if they are guided into making the right code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    gurpreet is right though: goto is another way to avoid using loops, though arguably all that happens is that the goto simulates a loop, but the same can be said of recursion, especially tail recursion.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Code:
    int biggest(int *array, int len)
    {
        int big;
    
        if(len == 1) return *array;
        big = biggest(array + 1, len - 1);
        return (array[0] > big) ? array[0] : big;
    }
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM