Advertisement
Eriziel

Array Homework

Jun 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.50 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 ConsoleApplication3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // 1. Stwórz tablicę od 500 do 0.
  14.             // 2. Stwórz tablicę, gdzie co 5-ty element ma wartość 1.
  15.             // 3. Stwórz tablicę przyjmującą tylko wartości 1 oraz -1.
  16.             // 4. Tablica wartości od 50 do 90, co drugą (50, 52, 54, etc...)
  17.             // 5. Oblicz sumę tablicy z zad. 4.
  18.             // 6. Oblicz sumę tablicy z zad. 2.
  19.             // 7. Stwórz dwie tablice (Jedna ma wartości -1, -2,-3,-4,...,-1000) (Druga ma wartości 1,2,3,4,...,1000)
  20.             // 8. To co w zad. 7 (Pierwsza przyjmuje wartości -2000 do -1001)
  21.             // 9. Tablica o rozm. 1000 i wszędzie przyjmuje wartość 0 poza i, gdzie i = 2^n.
  22.  
  23.             //1
  24.             Console.WriteLine("\n\nAd. 1\n");
  25.  
  26.             int size = 501;
  27.             int[] tab1 = new int[size];
  28.  
  29.             int i = tab1.Length - 1;
  30.  
  31.            while(i >= 0)
  32.             {
  33.                
  34.                 tab1[i] = i;
  35.                
  36.                 Console.Write($"{tab1[i]}, ");
  37.                 i--;
  38.             }
  39.  
  40.             //2
  41.             Console.WriteLine("\n\nAd. 2\n");
  42.  
  43.             int size2 = 10;
  44.             int[] tab2 = new int[size2];
  45.            
  46.             for (int j = 0; j < tab2.Length; j++)
  47.             {
  48.                
  49.                 if ((j + 1) % 5 == 0)
  50.                 {
  51.                     tab2[j] = 1;
  52.                 }
  53.  
  54.                 Console.Write($"{tab2[j]}, ");
  55.             }
  56.  
  57.  
  58.             //3
  59.             Console.WriteLine("\n\nAd. 3\n");
  60.  
  61.             int size3 = 10;
  62.             int[] tab3 = new int[size3];
  63.             for (int k = 0; k < tab3.Length; k++)
  64.             {
  65.                 if (k % 2 == 0)
  66.                 {
  67.                     tab3[k] = 1;
  68.                 }
  69.                 else
  70.                     tab3[k] = -1;
  71.  
  72.                 Console.Write($"{tab3[k]}, ");
  73.             }
  74.  
  75.             //4
  76.             Console.WriteLine("\n\nAd. 4\n");
  77.  
  78.             int size4 = (91 - 48) / 2;
  79.             int[] tab4 = new int[size4];
  80.             int valueI = 50;
  81.             int l = 0;
  82.  
  83.             for (; l < tab4.Length; l++)
  84.             {
  85.                 tab4[l] = valueI;
  86.                 valueI = valueI + 2;
  87.  
  88.                 Console.Write($"{tab4[l]}, ");
  89.             }
  90.  
  91.             //5
  92.             Console.WriteLine("\n\nAd. 5\n");
  93.  
  94.             int m = 0;
  95.             int summary1 = 0;
  96.  
  97.             while (m < tab4.Length)
  98.             {
  99.                 summary1 += tab4[m];
  100.                 m++;
  101.             }
  102.             Console.Write(summary1);
  103.            
  104.             //6
  105.             Console.WriteLine("\n\nAd. 6\n");
  106.  
  107.             int n = 0;
  108.             int summary2 = 0;
  109.  
  110.             while(n < tab2.Length)
  111.             {
  112.                 summary2 += tab2[n];
  113.                 n++;
  114.             }
  115.             Console.Write(summary2);
  116.  
  117.            
  118.            
  119.  
  120.  
  121.             //7
  122.             Console.WriteLine("\n\nAd. 7\n");
  123.  
  124.             int size7 = 1000;
  125.             int[] tab7 = new int[size7];
  126.             int[] tab7a = new int[size7];
  127.  
  128.             for (int o = 0; o < tab7.Length; o++)
  129.             {
  130.                 tab7[o] = o + 1;
  131.                 Console.Write($"{tab7[o]}, ");
  132.  
  133.             }
  134.             Console.WriteLine("\n");
  135.             for (int p = 0; p < tab7a.Length; p++)
  136.             {
  137.                 tab7a[p] = (p + 1) * (-1);
  138.                 Console.Write($"{tab7a[p]}, ");
  139.                
  140.             }
  141.  
  142.             //8
  143.             Console.WriteLine("\n\nAd. 8\n");
  144.  
  145.             int size8 = 1000;
  146.             int[] tab8 = new int[size8];
  147.             int s = -2000;
  148.             for (int r = 0; r < tab8.Length; r++)
  149.             {
  150.                 tab8[r] = s;
  151.                 s++;
  152.                 Console.Write($"{tab8[r]}, ");
  153.  
  154.             }
  155.  
  156.             //9
  157.             Console.WriteLine("\n\nAd. 9\n");
  158.  
  159.             int size9 = 1000;
  160.             int[] tab9 = new int[size9];
  161.             int u = 0;
  162.  
  163.             for (int t = 0; t < tab9.Length; t++)
  164.             {
  165.                    
  166.                if (t == Math.Pow(2,u))
  167.                 {
  168.                     tab9[t] = t;
  169.                     u++;
  170.                 }
  171.                 Console.Write(tab9[t]+" ");
  172.             }
  173.  
  174.             Console.ReadKey();
  175.  
  176.         }
  177.     }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement