Advertisement
VyaraG

SumOfNumbers

Nov 28th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using System;
  2.  
  3. //Write a program that enters a number n and after that enters more n numbers and calculates and prints their sum. Note that you may need to use a for-loop.
  4.  
  5. class SumOfNNumbers
  6. {
  7.     static void Main()
  8.     {
  9.         Console.Write("n = ");
  10.         int n = int.Parse(Console.ReadLine());
  11.         double sum = 0;
  12.         for (int i = 1; i <= n; i++)
  13.         {
  14.             Console.Write("number {0} = ", i);
  15.             double number = double.Parse(Console.ReadLine());
  16.             sum += number;
  17.         }
  18.         Console.WriteLine("Sum = {0}", sum);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement