https://cs50.harvard.edu/x/2023/labs/1/
Lab 1: Population Growth - CS50x 2023
Harvard University's introduction to the intellectual enterprises of computer science and the art of programming.
cs50.harvard.edu
제출한 답안
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// TODO: Prompt for start size
int start_size;
do
{
start_size = get_int("Start size: ");
}
while ( start_size < 9 );
// TODO: Prompt for end size
int end_size;
do
{
end_size = get_int("End size: ");
}
while ( end_size < start_size ); // 이 부분이 exit조건임에 유의!!
// TODO: Calculate number of years until we reach threshold
int size = start_size;
int year = 0;
while ( size < end_size )
{
int born_size = size / 3;
int dead_size = size / 4;
size = size + born_size - dead_size;
year = year + 1;
}
printf("Years: %i \n", year);
// TODO: Print number of years
}
do
{
end_size = get_int("End size: ");
}
while ( end_size < start_size ); // 이 부분이 exit조건임에 유의!!
위 부분이 헷갈려서 한참 돌았다 ㅠ