Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 445377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:21:52+00:00 2026-05-12T21:21:52+00:00

I am trying to find the max number in an array. I have created

  • 0

I am trying to find the max number in an array. I have created a function and I am using the following code:

int maxValue( int myArray [], int size)
{
    int i, maxValue;
    maxValue=myArray[0];

    //find the largest no
    for (i=0;i)
        {
        if (myArray[i]>maxValue)
        maxValue=myArray[i];
        }   
        return maxValue;
}

However I get a syntax error before ) token. What am I doing wrong and am I even doing this right? Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:21:52+00:00Added an answer on May 12, 2026 at 9:21 pm

    You must pass a valid array with at least one member to this function:

    #include<assert.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    
    int
    maxValue(int myArray[], size_t size) {
        /* enforce the contract */
        assert(myArray && size);
        size_t i;
        int maxValue = myArray[0];
    
        for (i = 1; i < size; ++i) {
            if ( myArray[i] > maxValue ) {
                maxValue = myArray[i];
            }
        }
        return maxValue;
    }
    
    int
    main(void) {
        int i;
        int x[] = {1, 2, 3, 4, 5};
        int *y = malloc(10 * sizeof(*y));
    
        srand(time(NULL));
    
        for (i = 0; i < 10; ++i) {
            y[i] = rand();
        }
    
        printf("Max of x is %d\n", maxValue(x, sizeof(x)/sizeof(x[0])));
        printf("Max of y is %d\n", maxValue(y, 10));
    
        return 0;
    }
    

    By definition, the size of an array cannot be negative. The appropriate variable for array sizes in C is size_t, use it.

    Your for loop can start with the second element of the array, because you have already initialized maxValue with the first element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find out programatically the max permgen and max heap size
I'm trying to find the max value contained in two separate fields of my
Trying to find the sqlserver adapter for rails on windows. I have tried getting
Trying to find an example that has css rollover using sprites & sliding door
I'm trying to find the best way to calculate the box size needed for
Basically I'm trying to get a rankings between 4 people. I have an array
I'm trying to find the number of occurrences of these ([0],[1],[2] etc) in an
here is my code trying to do reduction to find maximum of a 50
I'm trying to pass a pointer to an array of struct. This code should
I'm trying to find the maximum number of threads per process on a UNIX

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.