Advertisement
abasar

arrays #1 27/

Dec 27th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.85 KB | None | 0 0
  1. //#1
  2.             int[] arr = new int[10];
  3.             int[] rev = new int[10];
  4.             for (int i = 0; i < 10; i++)
  5.             {
  6.                 int num = int.Parse(Console.ReadLine());
  7.                 arr[i] = num;
  8.                 rev[9 - i] = num;
  9.             }
  10.             for (int i = 0;  i < 10; i++)
  11.                 Console.Write("{0,-3}", arr[i]);
  12.             Console.WriteLine();
  13.             Console.WriteLine();
  14.             for (int i = 0; i < 10; i++)
  15.                 Console.Write("{0,-3}", rev[i]);
  16.         }
  17. //#3
  18.             int[] a = new int[8];
  19.             for (int i = 0; i < a.Length; i++)
  20.                 a[i] = int.Parse(Console.ReadLine());
  21.             int counter = 0;
  22.             for (int i = 0; i < a.Length - 1; i++)
  23.                 if (a[i] > a[i + 1]) counter++;
  24.             Console.WriteLine(counter);
  25.  
  26. //#4
  27.             int[] a = new int[7];
  28.             for (int i = 0; i < a.Length; i++)
  29.                 a[i] = int.Parse(Console.ReadLine());
  30.             int counter = 0, counter2 = 0;
  31.             double avg = 0;
  32.             for (int i = 0; i < a.Length; i++)
  33.             {
  34.                 if (a[i] % 2 == 0)
  35.                     counter++;
  36.                 else
  37.                 {
  38.                     avg += a[i];
  39.                     counter2++;
  40.                 }
  41.             }
  42.             avg /= (double)counter2;
  43.             Console.WriteLine("even: {0}, average: {1}", counter, avg);
  44.  
  45. //#7
  46. //solution by Amit Lazar
  47.             int[] a = new int[5];
  48.             for (int i = 0; i < a.Length; i++)
  49.                 a[i] = int.Parse(Console.ReadLine());
  50.             bool different = true;
  51.             int j = 0;
  52.             while (j < a.Length - 1 && different == true)
  53.             {
  54.                 if (a[j] != a[j + 1])
  55.                     j++;
  56.                 else
  57.                     different = false;
  58.             }
  59.             Console.WriteLine(different);
  60. //#8
  61.             int[] a = new int[10];
  62.             Random rnd = new Random();
  63.             for (int i = 0; i < a.Length; i++)
  64.                 a[i] = rnd.Next(4, 28);
  65.             int times = 1, num = 0;
  66.             for (int i = 1; i < a.Length; i++)
  67.             {
  68.                 int lotime = 1;
  69.                 for (int j = 0; j < i; j++)
  70.                     if (a[j] == a[i]) lotime++;
  71.                 if (lotime >= times)
  72.                 {
  73.                     num = a[i];
  74.                     times = lotime;
  75.                 }
  76.                 Console.Write("{0,-3}", a[i]);
  77.             }
  78.             Console.WriteLine();
  79.             Console.WriteLine("times: {0}, num: {1}", times, num);
  80. //#9
  81. int[] a = new int[10];
  82.             int[] b = new int[10];
  83.             for (int i = 0; i < 10; i++)
  84.                 a[i] = int.Parse(Console.ReadLine());
  85.             for (int i = 0; i < 10; i++)
  86.                 b[i] = int.Parse(Console.ReadLine());
  87.             int[] d = new int[10];
  88.             int k = 0;
  89.             for (int i = 0; i < b.Length; i++)
  90.             {
  91.                 for (int j = 0; j < a.Length; j++)
  92.                 {
  93.                     if (a[i] == b[j])
  94.                     {
  95.                         d[k] = a[i];
  96.                         k++;
  97.                     }
  98.                 }
  99.             }
  100.             int[] c = new int[k];
  101.             for (int i = 0; i < c.Length; i++)
  102.                 c[i] = d[i];
  103.             for (int i = 0; i < c.Length; i++)
  104.                 Console.Write("{0, -3}", c[i]);
  105.  
  106. //#10
  107.             int[] a = new int[10];
  108.             for (int i = 0; i < a.Length; i++)
  109.                 a[i] = int.Parse(Console.ReadLine());
  110.             double avg = 0;
  111.             for (int i = 0; i < a.Length; i++)
  112.                 avg += a[i];
  113.             avg /= (double)a.Length;
  114.             Console.WriteLine(avg);
  115.             for (int i = 0; i < a.Length; i++)
  116.                 Console.WriteLine((double)a[i] - avg);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement