Advertisement
AndrewIvanov

Поиск максимального числа, оканчивающегося на единицу

May 25th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 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 ConsoleApplication12
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.            
  14.             Console.WriteLine("Укажите количество чисел");
  15.             int N = int.Parse(Console.ReadLine());
  16.             int i, j, dub, K, max; j = 0; K = 0;
  17.             if (N > 1000) Console.WriteLine("НЗД");
  18.             else
  19.             {
  20.                 Console.WriteLine("Укажите предел значений");
  21.                 int Lim = int.Parse(Console.ReadLine());
  22.  
  23.                 int[] A = new int[N];
  24.                 int[] B = new int[N];
  25.  
  26.                 Console.WriteLine("Введите числа");
  27.                 for (i = 0; i < N; i++)
  28.                 {
  29.                     A[i] = int.Parse(Console.ReadLine());
  30.                     if (A[i] > 3000 || A[i] < 0)
  31.                     {
  32.                         Console.WriteLine("НЗД, введите число ещё раз");
  33.                         A[i] = int.Parse(Console.ReadLine());
  34.                     }
  35.                 }
  36.                 for (i = 0; i < N; i++)
  37.                 {
  38.                     Math.DivRem(A[i], 10, out dub);
  39.                     if (dub == 1)
  40.                     {
  41.                         B[j] = A[i]; j++; K = j;
  42.                     }
  43.                 }
  44.                 if (K != 0)
  45.                 {
  46.                     max = B[0];
  47.                     for (j = 0; j < K; j++)
  48.                     {
  49.                         if (max < B[j])
  50.                             max = B[j];
  51.                     } Console.WriteLine("Наибольшее число = {0}", max); Console.ReadKey();
  52.                 }
  53.             }
  54.  
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement