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=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!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by dkalita
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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.