⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polulation.c

📁 You will write a program for calculating person s Body Mass Index (BMI). The following formula is us
💻 C
字号:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846 

int main(void){
	FILE *fp;
	char *filename = "population.txt";
	int month;
	float temperature[48], food[48];
	unsigned int population[48];
	population[0] = 0;
	for (month =0; month <48; month++){
		temperature[month] = 15.0 * sin(2.0 * PI * (month - 3) / 12.0) + 5.0;
		if (temperature[month]<0){
			food[month] =0;
			population[month+1]= population[month]* power(0.99, (temperature[month]+10)); 
		}
		else {
			food[month] = 1000.0 * sqrt(temperature[month]);
			population[month+1] = (population[month]*2)*power(0.99, (temperature[month]+10)); 
		}

	fp = fopen(filename, "w");
	if(fp == NULL){
		fprintf(stderr, "Error: Cannot open file!\n"); 
		return EXIT_FAILURE;
	}else{
		for (month =0; month <48; month++){
			fprintf (fp , "%d\t%.2lf\t%.0lf\t%u\n" , month , temperature[month] , food[month] , population[month]) ;
			fclose(fp) ;
	}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -