Angular, Blockchain, Science とか

Angular, Blockchain, Science全般 の情報を主に書いていきます。

C 最小値の探索

ただの最小値の探索です。

#include <stdio.h>

#define maxnumber 10

int minimum(int user_array[]);

main()
{
    int number[maxnumber];
    int index;
    
    printf("Give me nine numbers and I\'ll print them backwards \n");
    
    for(index=0; index<maxnumber; ++index)
    {
        printf("Number[%d] = ", index);
        scanf("%d", &number[index]);
    }
    
    printf("Thank you... \n");
    
    printf("Minimum number is %d\n", minimum(number));
}

int minimum(int user_array[])
{
    int index;
    int minimum;
    
    minimum = user_array[0];
    for(index=1; index<maxnumber; index++){
        if(user_array[index] < minimum){
            minimum = user_array[index];
        }
    }
    return minimum;
}