Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. /* //1.Napisz program który za pomocą instrukcji for dla danych wartości zmieniających się w przedziale od 0 do 10. Oblicz wartość funkcji y=3x.
  2.  
  3. static void Main(string[] args)
  4. {
  5.  
  6. Console.Write("podaj x= ");
  7. int x = Convert.ToInt32(Console.ReadLine());
  8.  
  9. for (int i = 0; i <= 10; i++)
  10. {
  11.  
  12.  
  13. int y = 3 * x;
  14.  
  15. Console.WriteLine("{0}", y);
  16. Console.ReadKey(true);
  17. break;
  18. }
  19.  
  20. }
  21. }
  22. }
  23. */
  24. //Zadeklaruj zmienną.Sprawdź czy wartość jest równa 1 lub 2. Użyj instrukcji switch.
  25.  
  26. /* static void Main(string[] args)
  27. {
  28.  
  29. Console.Write("podaj liczbe= ");
  30. int liczba = Convert.ToInt32(Console.ReadLine());
  31.  
  32. switch (liczba)
  33. {
  34.  
  35. case 1:
  36. Console.Write("jeden");
  37. break;
  38.  
  39. case 2:
  40. Console.Write("dwa");
  41. break;
  42.  
  43. default:
  44.  
  45. Console.Write("nieznana wartość");
  46. break;
  47. }
  48.  
  49. Console.ReadKey(true);
  50.  
  51.  
  52. }
  53. }
  54. }
  55. */
  56.  
  57. //3.Napisz program wyświetlający tabliczkę mnożenia dla liczbod 1 do 100. z wykorzystaniem podwójnej pętli for.
  58.  
  59. /* static void Main(string[] args)
  60. {
  61.  
  62.  
  63. for (int i = 1; i <= 10; i++)
  64. {
  65.  
  66. for (int a = 1; a <= 10; a++)
  67. {
  68.  
  69. int y = a * i;
  70.  
  71.  
  72. Console.Write("{0} ", y);
  73.  
  74. }
  75. Console.WriteLine("");
  76. }
  77. Console.ReadKey(true);
  78. }
  79.  
  80. }
  81. }
  82. */
  83. /* // 4.Napisz program który w zadeklarowanej tablicy 10x10 o nazwie macierz umieszcza na przekątnej liczbę 1 a poza nią 0. Program powinien obliczać sumę wyróżnionych elementów znajdujących się na jej przekątnej.
  84. static void Main(string[] args)
  85. {
  86. int[ , ] macierz = new int[10, 10];
  87.  
  88. for (int x = 0; x < 10; x++)
  89. {
  90. for (int y = 0; y < 10; y++)
  91. {
  92. macierz[x, y] = 0;
  93.  
  94. }
  95. }
  96.  
  97. for(int i=0;i<10;i++)
  98. {
  99. macierz[i, i] = 1;
  100. }
  101.  
  102. int licz = 0;
  103.  
  104. for (int x = 0; x < 10; x++)
  105. {
  106. for (int y = 0; y < 10; y++)
  107. {
  108. if(macierz[x, y] == 1) { licz++; }
  109.  
  110. }
  111. }
  112. Console.WriteLine("{0}\n", licz);
  113.  
  114.  
  115. for (int x = 0; x < 10; x++)
  116. {
  117. for (int y = 0; y < 10; y++)
  118. {
  119. Console.Write("{0} ", macierz[x , y]);
  120. }
  121.  
  122. Console.WriteLine("");
  123.  
  124. }
  125.  
  126.  
  127. Console.ReadKey(true);
  128. }
  129.  
  130. }
  131. }
  132. */
  133. // 5. Napisz funkcję która policzy 6 wyrazów ciągu Fibonnaciego i wypisze jego sumę.
  134.  
  135. static void Main(string[] args)
  136. {
  137.  
  138. Console.Write("podaj n= ");
  139. int n = Convert.ToInt32(Console.ReadLine());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement