Untitled

 avatar
unknown
java
2 years ago
1.0 kB
4
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int sum_iter(int);
int sum_formula(int);
int population_projection(double, double, double);

int input, sum;

int year_count;
double result;

double aop, gpy, mp;

int main(void) {
    /*printf("Indtast input> ");
    scanf("%d", &input);

    printf("\n%d", sum_iter(input));
    printf("\n%d", sum_formula(input));*/

    printf("Indtast amount_of_people, growth_per_year, max_people> ");
    scanf("%lf, %lf, %lf", &aop, &gpy, &mp);
    printf("\n%d", population_projection(aop, gpy, mp));
    return 0;
}

int sum_iter(int n){
    for (int i = 0; i <= n; i++){
        sum = sum + i;
    }
    return sum;
}

int sum_formula(int n){
    return (n + 1) * n / 2;
}

int population_projection(double amount_of_people,
                          double growth_per_year,
                          double max_people){
    result = amount_of_people;

    while (result <= max_people + 1){
        result *= (growth_per_year / 100 + 1);
        year_count++;
    }

    return year_count;
}