Advertisement
Guest User

Untitled

a guest
Jul 13th, 2013
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 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.  * Write a program that reads two integer numbers N and K and an array of N elements from the console.
  8.  * Find in the array those K elements that have maximal sum.
  9.  */
  10. namespace _6
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Console.Write("Enter N: ");
  17.             int N = int.Parse(Console.ReadLine());
  18.             Console.Write("Enter K: ");
  19.             int K = int.Parse(Console.ReadLine());
  20.             if (N >= K)
  21.             {
  22.                 int[] arr = new int[N];
  23.                 Console.WriteLine("Enter arr numbers: ");
  24.                 for (int count = 0; count < arr.Length; count++)
  25.                 {
  26.                     arr[count] = int.Parse(Console.ReadLine());
  27.                 }
  28.  
  29.                 Array.Sort(arr);
  30.                 for (int countAgain = N; countAgain >= K; countAgain--)
  31.                 {
  32.                     Console.WriteLine("Biggest numbers of K elements in the array are: {0}", arr[countAgain - 1]);                      
  33.                 }
  34.             }
  35.            
  36.             else
  37.                 Console.WriteLine("K cant be bigger then N");
  38.         }    
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement