Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. 1)
  2. C++
  3. #include "stdafx.h"
  4. #include "iostream"
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10. int x[10];
  11. int a = 0;
  12. for (int i = 1;i <= 10;i++)
  13. {
  14. if (i % 2 == 0)
  15. {
  16. x[a] = i;
  17. a++;
  18. }
  19. }
  20. for (int j = 0;j < a;j++)
  21. {
  22. cout << x[j] <<endl;
  23. }
  24. system("pause");
  25. return 0;
  26. }
  27.  
  28. C#
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Linq;
  32. using System.Text;
  33. using System.Threading.Tasks;
  34.  
  35. namespace Zad1_Csharp
  36. {
  37. class Program
  38. {
  39. static void Main(string[] args)
  40. {
  41. int[] x = new int[10];
  42. int a = 0;
  43. for(int i=1; i<=10;i++)
  44. {
  45. if(i%2==0)
  46. {
  47. x[a] = i;
  48. a++;
  49. }
  50. }
  51. for(int j=0; j<a;j++)
  52. {
  53. Console.WriteLine(x[j]);
  54. }
  55. Console.ReadKey();
  56. }
  57. }
  58. }
  59.  
  60. 3)
  61. C++
  62. #include "stdafx.h"
  63. #include "iostream"
  64. #include "fstream"
  65. #include "string"
  66. using namespace std;
  67.  
  68.  
  69. int main()
  70. {
  71. string x[5];
  72. x[0] = "Osnove programiranja";
  73. x[1] = "Racunalni engleski 1";
  74. x[2] = "Matematika";
  75. x[3] = "Uvod u ICT";
  76. x[4] = "Algoritmi i strukture podataka";
  77. ofstream oDat;
  78. oDat.open("D:\\Games\\Kolegiji_polje.txt");
  79. for (int i = 0; i < 5;i++)
  80. {
  81. oDat << x[i] << endl;
  82. }
  83. oDat.close();
  84. return 0;
  85. }
  86.  
  87. C#
  88. using System;
  89. using System.Collections.Generic;
  90. using System.Linq;
  91. using System.Text;
  92. using System.Threading.Tasks;
  93. using System.IO;
  94.  
  95. namespace Zad3_Csharp
  96. {
  97. class Program
  98. {
  99. static void Main(string[] args)
  100. {
  101. string [] x = new string[5];
  102. x[0] = "Osnove programiranja";
  103. x[1] = "Racunalni engleski 1";
  104. x[2] = "Matematika";
  105. x[3] = "Uvod u ICT";
  106. x[4] = "Algoritmi i strukture podataka";
  107. string path = @"D:\Games\Kolegiji_polje2.txt";
  108. StreamWriter oDat = new StreamWriter(path, true);
  109. for (int i = 0; i < 5; i++)
  110. {
  111. oDat.WriteLine(x[i]);
  112. }
  113. oDat.Flush();
  114. oDat.Close();
  115. }
  116. }
  117. }
  118.  
  119.  
  120. 4)
  121. C++
  122. #include "stdafx.h"
  123. #include "iostream"
  124. using namespace std;
  125.  
  126. int main()
  127. {
  128. int brojevi[10];
  129. for (int i = 0; i < 10;i++)
  130. {
  131. cin >> brojevi[i];
  132. }
  133. for (int j = 0; j < 10;j++)
  134. {
  135. if (j % 2 != 0)
  136. {
  137. cout << brojevi[j] << endl;
  138. }
  139. }
  140. system("pause");
  141. return 0;
  142. }
  143.  
  144. C#
  145. using System;
  146. using System.Collections.Generic;
  147. using System.Linq;
  148. using System.Text;
  149. using System.Threading.Tasks;
  150.  
  151. namespace Zad4_Csharp
  152. {
  153. class Program
  154. {
  155. static void Main(string[] args)
  156. {
  157. int[] brojevi = new int[10];
  158. for(int i=0; i<10;i++)
  159. {
  160. brojevi[i] = Convert.ToInt32(Console.ReadLine());
  161. }
  162. for (int j = 0; j < 10; j++)
  163. {
  164. if (j % 2 != 0)
  165. {
  166. Console.WriteLine(brojevi[j]);
  167. }
  168. }
  169. Console.ReadKey();
  170. }
  171. }
  172. }
  173.  
  174. 7)
  175. C#
  176. using System;
  177. using System.Collections.Generic;
  178. using System.Linq;
  179. using System.Text;
  180. using System.Threading.Tasks;
  181.  
  182. namespace Zad7_Csharp
  183. {
  184. class Program
  185. {
  186. static void Main(string[] args)
  187. {
  188. List<string> x = new List<string>();
  189. x.Add("B");
  190. x.Add("C");
  191. x.Add("A");
  192. x.Sort();
  193. foreach (string value in x)
  194. {
  195. Console.WriteLine(value);
  196. }
  197. Console.ReadKey();
  198. }
  199. }
  200. }
  201.  
  202. 8)
  203. C++
  204. #include "stdafx.h"
  205. #include "iostream"
  206. #include "vector"
  207. #include "string"
  208. #include "fstream"
  209. using namespace std;
  210.  
  211. int main()
  212. {
  213. vector<string> x;
  214. x.push_back("Osnove programiranja");
  215. x.push_back("Racunalni engleski 1");
  216. x.push_back("Matematika");
  217. x.push_back("Uvod u ICT");
  218. x.push_back("Algoritmi i strukture podataka");
  219. ofstream oDat;
  220. oDat.open("D:\\Games\\Kolegiji_vektor.txt");
  221. for (int i = 0; i < x.size();i++)
  222. {
  223. oDat << x[i] << endl;
  224. }
  225. oDat.close();
  226. return 0;
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement