Advertisement
albertbg

SumOfFiveNumbers

Jun 19th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _07_SumOfFiveNumbers
  4. {
  5.     class SumOfFive
  6.     {
  7.         static void Main()
  8.         {            
  9.             double a = 0;
  10.             double b = 0;
  11.             double sum=0;
  12.             Console.WriteLine("Enter 5 numbers separated by a space");
  13.             string[] userInput = Console.ReadLine().Split();
  14.  
  15.              for (int i = 0; i < 5; i++)
  16.                 {
  17.                     a = Convert.ToDouble(userInput[i]);
  18.                     sum = a + b;
  19.                     b = sum;
  20.                 }
  21.  
  22.             Console.WriteLine("Sum of first five Numbers is {0}",sum);
  23.         }        
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement