用C语言设置指数增长函数X = a(1 + b)^ t

问题描述 投票:0回答:1

我正在编写一个程序,以使用指数增长函数(X = a(1 + b)^ t)跟踪一周内制作的矩形的数量。一个人每天可以制作60个矩形。

我在开始解决此问题时遇到困难,请提供一些指导。

我当时正在考虑使用math.h和pow,类似这样(此代码未编译)


#include <math.h>
#include <stdio.h>
#include <stdlib.h>


int main() {

    int initial_POPULATION;
    int time_INTERVAL; 
    double growth_RATE; 
    //exponential growth function X = a(1 + b)^t
    //initial_POPULATION = a;
    //growth_RATE = b;
    //time_INTERVAL = t

    printf("How many people are making rectangles at the 
    biginning of the week?\n");
    scanf("%d", &initial_POPULATION);


    printf("How many people are making rectangles each day? 
    \n");
    scanf("%1f", &growth_RATE);

    //Exponential growth function X = a(1+b)^t
    printf("%d rectangles will be made this week!\n",
        initial_POPULATION(pow(1+growth_RATE),time_INTERVAL));

    return 0;

}

c exponential pow math.h
1个回答
0
投票

如果您使用的是UNIX,您是否尝试过像这样编译?

gcc /path/to/file.c -lm -o path/to/file
© www.soinside.com 2019 - 2024. All rights reserved.