Advertisement
silvana1303

print and sum (with array)

May 22nd, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. namespace whatevs
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int start = int.Parse(Console.ReadLine());
  13.             int end = int.Parse(Console.ReadLine());
  14.  
  15.             int n = end - start + 1;
  16.  
  17.             int[] arr = new int[n];
  18.  
  19.             for (int i = 0; i < n ; i++)
  20.             {
  21.                 arr[i] = i + start;
  22.             }
  23.  
  24.             int sum = arr.Sum();
  25.  
  26.             string[] numbers = arr.Select(x => x.ToString()).ToArray();
  27.  
  28.             string answer = string.Join(" ", numbers.ToArray());
  29.  
  30.             Console.WriteLine(answer);
  31.             Console.WriteLine($"Sum: {sum}");
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement