Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. setlocale(LC_ALL, "rus");
  9. char buffstr[100];
  10. ifstream fin("text.txt");
  11. while (!fin.eof())
  12. {
  13. string s;
  14. getline(fin, s);
  15. int flag = -1;
  16. int j = 0, i = 0;
  17. while (s[i]) {
  18. if (s[i] == '"')
  19. if (flag < 0) flag = i;
  20. else
  21. {
  22. for (j = flag; j <= i; j++) cout << s[j];
  23. cout << " ";
  24. flag = -1;
  25. }
  26. i++;
  27. }
  28. }
  29. cout << endl;
  30. fin.close();
  31. system("pause");
  32. return 0;
  33. }
  34.  
  35.  
  36. 1) #include <iostream>
  37. using namespace std;
  38. int nod(int a, int b)
  39. {
  40. while (a != b) {
  41. if (a > b) {
  42. int tmp = a;
  43. a = b;
  44. b = tmp;
  45. }
  46. b = b - a;
  47. }
  48. return a;
  49. }
  50. long nod(long a, long b)
  51. {
  52. while (a != b) {
  53. if (a > b) {
  54. long tmp = a;
  55. a = b;
  56. b = tmp;
  57. }
  58. b = b - a;
  59. }
  60. return a;
  61. }
  62. float nod(float a, float b)
  63. {
  64. while (a != b) {
  65. if (a > b) {
  66. float tmp = a;
  67. a = b;
  68. b = tmp;
  69. }
  70. b = b - a;
  71. }
  72. return a;
  73. }
  74. double nod(double a, double b)
  75. {
  76. while (a != b) {
  77. if (a > b) {
  78. double tmp = a;
  79. a = b;
  80. b = tmp;
  81. }
  82. b = b - a;
  83. }
  84. return a;
  85. }
  86. int main()
  87. {
  88. setlocale(LC_ALL, "rus");
  89. cout << "Введите два int числа: ";
  90. int ia, ib;
  91. cin >> ia >> ib;
  92. cout << "НОД = " << nod(ia, ib) << endl;
  93. cout << "Введите два long числа: ";
  94. long la, lb;
  95. cin >> la >> lb;
  96. cout << "НОД = " << nod(la, lb) << endl;
  97. cout << "Введите два float числа: ";
  98. int fa, fb;
  99. cin >> fa >> fb;
  100. cout << "НОД = " << nod(fa, fb) << endl;
  101. cout << "Введите два double числа: ";
  102. double da, db;
  103. cin >> da >> db;
  104. cout << "НОД = " << nod(da, db) << endl;
  105. system("pause");
  106. return 0;
  107. }
  108. 2) #include <iostream>
  109. using namespace std;
  110.  
  111. template <class array_type>
  112. array_type sum(array_type *a, int n)
  113. {
  114. array_type s = 0;
  115. for (int i = 0; i < n; i++)
  116. {
  117. s += a[i];
  118. }
  119. return s;
  120. }
  121.  
  122. int main()
  123. {
  124. setlocale(LC_ALL, "rus");
  125. int a[10] = {};
  126. float b[10] = {};
  127. double c[10] = {};
  128. cout << "Введите N = ";
  129. int n;
  130. cin >> n;
  131. cout << "\nВведите int массив ";
  132. for (int i = 0; i < n; i++) cin >> a[i];
  133. cout << "\n Сумма = " << sum(a, n);
  134. cout << "\nВведите float массив ";
  135. for (int i = 0; i < n; i++) cin >> b[i];
  136. cout << "\n Сумма = " << sum(b, n);
  137. cout << "\nВведите double массив ";
  138. for (int i = 0; i < n; i++) cin >> c[i];
  139. cout << "\n Сумма = " << sum(c, n) << endl;
  140. system("pause");
  141. return 0;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement