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

Ask A Question

Stats

  • Questions 253k
  • Answers 253k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You will need to create a new Visual Studio project… May 13, 2026 at 9:55 am
  • Editorial Team
    Editorial Team added an answer In a talk available at YUI Theater, Joseph Smarr talks… May 13, 2026 at 9:55 am
  • Editorial Team
    Editorial Team added an answer Alexandr Ciornii's point about definedness vs. existence is a very… May 13, 2026 at 9:55 am

Related Questions

I have been reading a lot about Reinforcement Learning lately, and I have found
I am looking to develop a system in which i need to assign every
I have a table relationship that looks like the following: barn ------ PK barn_id
Given any iterable, for example: ABCDEF Treating it almost like a numeral system as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.