I'm trying to find the largest int in an array and then print it out to the screen. Here is what I have so far:

void LargeNumber(int numbers[], int k){
    int len = k;
    int i = 0;
    int big_num = 0;
    for(i=0; i<len; i++) {
        printf("i is: %d\n", i);
        if(numbers[big_num] > numbers[i]){
            big_num = numbers[i];
        }
        if(numbers[big_num] <= numbers[i]){
            printf("Still looking for largest number. \n");
        }
        }
    printf("The largest number is: %d\n", big_num);

}

What am I doing wrong? I think it's to do with the comparison between big_num and i but I am having a brain fart and can't work through it. Any help/input would be greatly appreciatted!

I figured it out...

All I had to do was set big_num = numbers[0].

:)

I'm trying to find the largest int in an array and then print it out to the screen. Here is what I have so far:

void LargeNumber(int numbers[], int k){
    int len = k;
    int i = 0;
    int big_num = 0;
    for(i=1; i<len; i++) {
        printf("i is: %d\n", i);
        if(numbers[big_num] < numbers[i]){
            big_num = i;
        }
        if(numbers[big_num] >= numbers[i]){
            printf("Still looking for largest number. \n");
        }
    }
    printf("The largest number is: %d\n", numbers[big_num]);

}

What am I doing wrong? I think it's to do with the comparison between big_num and i but I am having a brain fart and can't work through it. Any help/input would be greatly appreciatted!

hi, i have made correction to your code. Please check it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.