Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. using namespace std;
  2.  
  3. int main()
  4. {
  5. srand(time(NULL));
  6. int n;
  7. cout << "Podaj ilosc losowanych iczb: " << endl;
  8. cin >> n;
  9. FILE *plik = nullptr;
  10. int dane;
  11. char znak;
  12. if ((plik = fopen("losowanie.txt", "w+")) != nullptr)
  13. {
  14. for (int i = 1; i <= n; ++i)
  15. fprintf(plik, " %d", rand() % 10);
  16. for (int i = 1; i <= n; ++i)
  17. {
  18. fseek(plik, -(i * 2), SEEK_END);
  19. fscanf(plik, "%d", &dane);
  20. cout << dane << " " ;
  21. }
  22. fclose(plik);
  23. }
  24. else
  25. cout << "Nie udalo sie otworzyc pliku na dysku!\n";
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement