Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 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 programcic
  8. {
  9. class Program
  10. {
  11. static void Obrnuti() // funkcija da obrne ime i prezime koje si uneo, opcija 2 sa testa
  12. {
  13. Console.WriteLine("Unesi ime");
  14. string ime = Console.ReadLine();
  15. Console.WriteLine("Unesi prezime:");
  16. string prezime = Console.ReadLine();
  17. string obrnuti = ime + prezime;
  18. string djoka = "";
  19. for(int i = obrnuti.Length-1; i>=0; i--)
  20. {
  21. djoka = djoka + obrnuti[i];
  22. }
  23. Console.WriteLine("Obrnuti je:");
  24. foreach(var s in djoka)
  25. {
  26. Console.Write(s);
  27. }
  28.  
  29.  
  30. }
  31.  
  32.  
  33. static void Proveri() // funkcija da proveri da li je proizvod godine,meseca i dana deljiva sa unetim brojem
  34. {
  35. int g, m, d;
  36. int broj;
  37. Console.WriteLine("Unesi godinu:");
  38. g = int.Parse(Console.ReadLine());
  39. Console.WriteLine("Unesi mesec:");
  40. m = int.Parse(Console.ReadLine());
  41. Console.WriteLine("Unesi dan:");
  42. d = int.Parse(Console.ReadLine());
  43. Console.WriteLine("Unesi broj:");
  44. broj = int.Parse(Console.ReadLine());
  45. int proizvod = g * m * d;
  46. if (proizvod % broj == 0)
  47. {
  48. Console.WriteLine("Deljiv je:");
  49. }
  50. else
  51. {
  52. Console.WriteLine("nije deljiv:");
  53. }
  54.  
  55. }
  56. static void UnosNiza() funkcija za unos nekog random niza
  57. {
  58. Console.WriteLine("Unesite clanove niza:");
  59. int n = int.Parse(Console.ReadLine());
  60. int[] niz = new int[n];
  61. for (int i = 0; i < n; i++)
  62. {
  63. Console.WriteLine("element[{0}] =", i);
  64. niz[i] = int.Parse(Console.ReadLine());
  65. }
  66. Sort(niz); // poziv funkcije sort
  67.  
  68.  
  69.  
  70. }
  71. static void Sort(int[] arr) // funkcija za sortiranje bilo kog niza
  72. {
  73. Console.WriteLine("Sortiran niz je:");
  74. for (int i = 0; i < arr.Length; i++)
  75. {
  76. for (int j = i + 1; j < arr.Length; j++)
  77. {
  78. if (arr[i] > arr[j])
  79. {
  80. int tmp = arr[i];
  81. arr[i] = arr[j];
  82. arr[j] = tmp;
  83. }
  84. }
  85. }
  86. foreach(int b in arr)
  87. {
  88. Console.WriteLine("{0}\t", b);
  89. }
  90. }
  91.  
  92. static void UnosMatrice() // funkcija za unos matrice A i B
  93. {
  94. Console.WriteLine("Unesi dimenziju matrice:");
  95. int n = int.Parse(Console.ReadLine());
  96. int[,] matrica_A = new int[n, n];
  97. Console.WriteLine("Unesi clanove matrice:");
  98. for (int i = 0; i < n; i++)
  99. {
  100. for (int j = 0; j < n; j++)
  101. {
  102. Console.WriteLine("element[{0},{1}]", i, j);
  103. matrica_A[i, j] = int.Parse(Console.ReadLine());
  104. }
  105. }
  106. Console.WriteLine("Matrica A je :"); // ispis matrice A
  107. for (int i = 0; i < n; i++)
  108. {
  109. for (int j = 0; j < n; j++)
  110. {
  111. Console.Write("{0}\t", matrica_A[i, j]);
  112. }
  113. Console.WriteLine();
  114. }
  115. int[,] matrica_B = new int[n, n];
  116.  
  117. for (int i = 0; i < n; i++)
  118. {
  119. for (int j = 0; j < n; j++)
  120. {
  121.  
  122. matrica_B[i, j] = matrica_A[i, j] * j; //logika za punjenje matrice B
  123. }
  124.  
  125. }
  126. Console.WriteLine("Matrica B je :"); // ispis matrice B
  127. for (int i = 0; i < n; i++)
  128. {
  129. for (int j = 0; j < n; j++)
  130. {
  131. Console.Write("{0}\t", matrica_B[i, j]);
  132. }
  133. Console.WriteLine();
  134.  
  135. }
  136.  
  137.  
  138. for (int i = 0; i < n; i++)
  139. {
  140. for (int j = 0; j < n; j++)
  141. {
  142.  
  143. matrica_B[i, j] += matrica_A[i, j]; // sabiranje A i B
  144. }
  145. }
  146. Console.WriteLine("Zbir je:");
  147. for ( int i = 0; i < n; i++) //ispis A i B
  148. {
  149. for (int j = 0; j < n; j++)
  150. {
  151. Console.Write("{0}\t", matrica_B[i, j]);
  152. }
  153. Console.WriteLine();
  154.  
  155.  
  156. }
  157. }
  158.  
  159. static void Main(string[] args)
  160. {
  161. Console.WriteLine("Meni");
  162. Console.WriteLine("1. Unesite niz i sortirajte ga:");
  163. Console.WriteLine("2. Saberite 2 matrice, pri čemu se B dobija na posebni nacin:");
  164. Console.WriteLine("3. Proverite da li je proizvod godine,meseca i dana deljivo 3:");
  165. Console.WriteLine("4. Obrni ime i prezime koje si uneo:");
  166. Console.WriteLine("5. Za izlaz:");
  167.  
  168.  
  169. while (true)
  170. {
  171. Console.WriteLine("Unesite opciju koju zelite:");
  172. int option = int.Parse(Console.ReadLine());
  173. switch (option)
  174. {
  175. case 1: UnosNiza(); break; // POZIVANJE FUNKCIJA U MAIN-U i kraj programa
  176. case 2: UnosMatrice(); break;
  177. case 3: Proveri(); break;
  178. case 4: Obrnuti(); break;
  179. case 5: return;
  180. default: Console.WriteLine("Probaj opet"); break;
  181.  
  182.  
  183. }
  184. Console.WriteLine();
  185.  
  186. }
  187.  
  188. }
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement