見出し画像

プログラミング学習の記録 #019(C)

取り組んでいる研究において、第一段階となる部分については、おおよそ完成したと言えるところまできた。その研究で用いている関数のうち、汎用性が高いと思われる関数について、以下に記録しておこうと思う。プログラミング言語は、C言語を用いている。

任意の範囲でランダムな整数を出力する関数

#include <stdio.h>
#include <time.h>

int get_random(int min, int max)
{
    int number;
    number = min + ( rand() % (max - min + 1) ) ;
    return number;
}

int main()
{
    srand((unsigned int)time(NULL));

    int number;

    number = get_random(1,100) ;
    printf("number = %3d\n",number);

    printf("HAPPY SMILE (^_^)v\n");
    return 0;
}

生物種の絶滅判定をする関数

#include <stdio.h>

double judge_extinction(double biomass,double weight)
{
    // If the biomass is less than the indivisual mass, the biomass becomes zero.

    double result;
    if(biomass < weight)
    {
        result = 0.00000 ;
    }else
    {
        result = biomass ;
    }
    return result;
}

int main()
{
    double mass,weight;

    mass = 10.000 ;                         // Biomass of the species in the time.
    weight = 0.010 ;                        // Indivisual mass.

    mass = judge_extinction(mass,weight) ;

    printf("mass = %7.3f\n",mass);

    printf("HAPPY SMILE (^_^)v\n");
    return 0;
}

-----

動け!タイムライン

動物園か水族館にいきたいですね。