Results 1 to 3 of 3

Thread: C code array help.

  1. #1
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,668
    Rep Power
    5

    C code array help.

    How do we find the largest term in an array ?

  2. #2
    Senior Member KingOfActing's Avatar
    Join Date
    Oct 2015
    HSC
    2016
    Gender
    Male
    Location
    Sydney
    Posts
    963
    Rep Power
    2

    Re: C code array help.

    Quote Originally Posted by Drsoccerball View Post
    How do we find the largest term in an array ?
    I don't know C but the pseudocode is:

    Code:
    int temp = array[0]
    for each int i in array
        if (i > temp)
        {
            temp = i;
        }
    return temp
    I tried to learn C syntax for this:

    Code:
    int temp = array[0];
    int size = sizeof(array)/sizeof(int);
    
    for(int index = 0; index < size; index++)
    {
        if(array[index] > maximum)
            maximum = array[index];
    }
    return maximum;
    Last edited by KingOfActing; 23 Apr 2016 at 7:36 PM.
    2015 HSC
    Mathematics 2U
    2016 HSC
    Advanced English, Drama, Maths 3U, Maths 4U, Music 2, Extension Music, Chemistry, Software Design & Development
    Currently studying
    Advanced Mathematics (Hons)/Computer Science @ UNSW (2017– )

  3. #3
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,668
    Rep Power
    5

    Re: C code array help.

    Quote Originally Posted by KingOfActing View Post
    I don't know C but the pseudocode is:

    Code:
    int temp = array[0]
    for each int i in array
        if (i > temp)
        {
            temp = i;
        }
    return temp
    ahaha thanks i figured it out. that wouldn't find the max number ^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •