Advertisement
Hazem3529

Untitled

Jun 4th, 2015
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace populationInEgypt
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double[] pop = new double[4];
  14.  
  15.             for (int i = 0; i < pop.Length; i++)
  16.             {
  17.                 Console.Write("enter the population of year 200"+(i+1)+" : ");
  18.                 pop[i] = double.Parse(Console.ReadLine());
  19.                 Console.WriteLine();
  20.             }
  21.             double rate = 0.0;
  22.            
  23.             for (int i = 0; i < pop.Length; i++)
  24.             {
  25.                 if (i == 0)
  26.                 {
  27.                     Console.WriteLine("200{0}  | {1}    | {2} %", i + 1, pop[i], rate);
  28.  
  29.                 }
  30.                 else if (i < pop.Length)
  31.                 {
  32.                     rate = (pop[i] - pop[i-1]) / pop[i-1];
  33.                     Console.WriteLine("200{0}  | {1}  | {2} %", i + 1, pop[i], rate);
  34.  
  35.                 }
  36.  
  37.                 else
  38.                 {
  39.                     rate = (pop[i + 1] - pop[i]) / pop[i];
  40.                     Console.WriteLine("200{0}  | {1}    | {2} %", i + 1, pop[i], rate);
  41.  
  42.  
  43.                 }
  44.  
  45.  
  46.                 }
  47.  
  48.          
  49.  
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement