Advertisement
pupesko

SoftUni - 4.9* Sum of n Numbers

Oct 1st, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. // 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.
  2.  
  3. using System;
  4.  
  5. class SumOfNnums
  6. {
  7.     static void Main()
  8.     {
  9.         Console.Write("How many numbers you want to enter: ");
  10.         string display = Console.ReadLine();
  11.         double a = double.Parse(display);
  12.  
  13.         double sum = 0;
  14.        
  15.         for (int i = 0; i < a; i++)
  16.         {
  17.             Console.Write("Enter number: ");
  18.             string numbs = Console.ReadLine();
  19.             double newnumbs = double.Parse(numbs);
  20.  
  21.             sum = sum + newnumbs;
  22.         }
  23.  
  24.         Console.WriteLine("The sum is: " + sum);
  25.     }      
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement