CS50-Week1
最后更新时间:
文章总字数:
预计阅读时间:
Lab1 C:Population Growth
How to do in this Lab
- Log into cs50 online devEnviroment
- Log into submitSystem
- When you finish any Labs,execute
check50
in teminal follow the sign$
- After pass the check,execute
style50
to decrate your code,and then submit by the commandsubmit50
.You can see practiced examples below right now.
Lab 1
Before the question
Input
mkdir population
to make a dir(i.e. directory) for your code by terminal.Then execute
cd population
to enter the dir just created,and you should see the prompt turn topopulation/ $
.Type
wget https://cdn.cs50.net/2022/fall/labs/1/population.c
from CS50 .You can have a look what inside by typing
ls
,then usecode population.c
to start your coding.
Background
Say we have a population of n llamas. Each year, n / 3 new llamas are born, and n / 4 llamas pass away.
For example, if we were to start with n = 1200 llamas, then in the first year, 1200 / 3 = 400 new llamas would be born and 1200 / 4 = 300 llamas would pass away. At the end of that year, we would have 1200 + 400 - 300 = 1300 llamas.
To try another example, if we were to start with n = 1000 llamas, at the end of the year, we would have 1000 / 3 = 333.33 new llamas. We can’t have a decimal portion of a llama, though, so we’ll truncate the decimal to get 333 new llamas born. 1000 / 4 = 250 llamas will pass away, so we’ll end up with a total of 1000 + 333 - 250 = 1083 llamas at the end of the year.
My Thoughts
Easy to understand the question,every year the number of llamas will be plused 1/3 and at the same time mintued 1/4.
We want to know after how many years that numbern
do equal the given numberm
,and output the years.
After finishing the code ,time to check,debug,style and submit.
test before check in
1 |
|
As soon your code works,you can check and so forth.
Following the commend below steo by step,and remember you are in the right dir.
1 |
|
Here are my final code styled by the CS50.
1 |
|