Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- /*
- * Write a program that reads two integer numbers N and K and an array of N elements from the console.
- * Find in the array those K elements that have maximal sum.
- */
- namespace _6
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Enter N: ");
- int N = int.Parse(Console.ReadLine());
- Console.Write("Enter K: ");
- int K = int.Parse(Console.ReadLine());
- if (N >= K)
- {
- int[] arr = new int[N];
- Console.WriteLine("Enter arr numbers: ");
- for (int count = 0; count < arr.Length; count++)
- {
- arr[count] = int.Parse(Console.ReadLine());
- }
- Array.Sort(arr);
- for (int countAgain = N; countAgain >= K; countAgain--)
- {
- Console.WriteLine("Biggest numbers of K elements in the array are: {0}", arr[countAgain - 1]);
- }
- }
- else
- Console.WriteLine("K cant be bigger then N");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement