Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fstream>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. void fill_in(int *a, int N, ifstream &file)
  7. {
  8. for (int i = 0; i < N; i++)
  9. {
  10. file >> a[i];
  11. cout << "F[" << i << "] = " << a[i] << endl;
  12. }
  13. }
  14.  
  15. void simillar_iF(int *a, int N)
  16. {
  17. for (int i = 0; i < N; i++)
  18. {
  19. if (i == a[i]) cout << "F[" << i << "] = " << a[i] << endl;;
  20. }
  21. }
  22.  
  23. int main()
  24. {
  25. setlocale(0, "Rus");
  26. ifstream file("J:\\Универ\\Программирование\\Практика_txt\\z_5.txt");
  27. if (file.is_open())
  28. {
  29. cout << "Файл открыт" << endl;
  30. const int N = 100;
  31. int F[N];
  32. cout << "Массив F: " << endl;
  33. fill_in(F, N, file);
  34. cout << endl << "Элементы, совпадающие с индексами: ";
  35. simillar_iF(F, N);
  36. system("pause");
  37. return 0;
  38. }
  39. else
  40. {
  41. cout << "Файл не открыт" << endl;
  42. system("pause");
  43. return 0;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement