Advertisement
laptrinhcuocsong

[Bài 8] Viết chương trình tính dân số của một thành phố sau

Jul 31st, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.30 KB | None | 0 0
  1. --------------------------------------------------------------------
  2. LIÊN HỆ
  3. Email: toichacchanthaydoi@gmail.com
  4. Facebook: https://www.facebook.com/son.trinhtrong.14
  5. FanPage: https://www.facebook.com/laptrinhchocuocsong
  6. Google+: https://plus.google.com/108976316226450934290/posts
  7. Điện thoại: 01696003856
  8.  
  9. Lưu ý: Code được viết trên phần mềm Visual Stdio 2015.
  10. --------------------------------------------------------------------
  11.  
  12. #define _CRT_SECURE_NO_WARNINGS
  13.  
  14. #include <stdio.h>
  15. #include <conio.h>
  16.  
  17. int main() {
  18.  
  19.     float currentPopulation = 6000000;
  20.  
  21.     /* Case 1: Beginner no use for loop
  22.     // After 1 years
  23.     currentPopulation += (currentPopulation * 0.018);
  24.  
  25.     printf("\nAfter 1 years the population is: %f", currentPopulation);
  26.  
  27.     // After 2 years
  28.     currentPopulation += (currentPopulation * 0.018);
  29.  
  30.     printf("\nAfter 2 years the population is: %f", currentPopulation);
  31.  
  32.     // After 3 years
  33.     currentPopulation += (currentPopulation * 0.018);
  34.  
  35.     printf("\nAfter 3 years the population is: %f", currentPopulation);
  36.  
  37.     // After 4 years
  38.     currentPopulation += (currentPopulation * 0.018);
  39.  
  40.     printf("\nAfter 4 years the population is: %f", currentPopulation);
  41.  
  42.     // After 5 years
  43.     currentPopulation += (currentPopulation * 0.018);
  44.  
  45.     printf("\nAfter 5 years the population is: %f", currentPopulation);
  46.  
  47.     // After 6 years
  48.     currentPopulation += (currentPopulation * 0.018);
  49.  
  50.     printf("\nAfter 6 years the population is: %f", currentPopulation);
  51.  
  52.     // After 7 years
  53.     currentPopulation += (currentPopulation * 0.018);
  54.  
  55.     printf("\nAfter 7 years the population is: %f", currentPopulation);
  56.  
  57.     // After 8 years
  58.     currentPopulation += (currentPopulation * 0.018);
  59.  
  60.     printf("\nAfter 8 years the population is: %f", currentPopulation);
  61.  
  62.     // After 9 years
  63.     currentPopulation += (currentPopulation * 0.018);
  64.  
  65.     printf("\nAfter 9 years the population is: %f", currentPopulation);
  66.  
  67.     // After 10 years
  68.     currentPopulation += (currentPopulation * 0.018);
  69.  
  70.     printf("\nAfter 10 years the population is: %f", currentPopulation);
  71.  
  72.     */
  73.  
  74.     // Case 2: Use for loop
  75.     int i;
  76.     for (i = 1; i <= 10; ++i) {
  77.         currentPopulation += currentPopulation * 0.018;
  78.     }
  79.  
  80.     printf("\nAfter 10 years the population is: %f", currentPopulation);
  81.  
  82.     //  Note: portion only natural results
  83.     _getch();
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement