anizko

04. Print and sum

May 19th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 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 _4.Print_and_Sum
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             {
  15.                 int NumStart = int.Parse(Console.ReadLine());
  16.                 int NumEnd = int.Parse(Console.ReadLine());
  17.  
  18.                 int Sum = 0;
  19.  
  20.                 for (int i = NumStart; i <= NumEnd; i++)
  21.                 {
  22.  
  23.                     Console.Write(i + " ");
  24.                     Sum += i;
  25.                     if (i== NumEnd)
  26.                     {
  27.                         Console.WriteLine();
  28.                     }
  29.                 }
  30.                 Console.WriteLine($"Sum: {Sum}");
  31.  
  32.  
  33.  
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment