Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7. FILE *input = fopen("input.txt", "r");
  8. FILE *output = fopen("output.txt", "w");
  9. if (!input) {
  10. printf("File input not found\n");
  11. fclose(input);
  12. fclose(output);
  13. exit(1);
  14. }
  15. if (!output) {
  16. printf("Can't create output file\n");
  17. fclose(input);
  18. fclose(output);
  19. exit(2);
  20. }
  21. int n, i;
  22. float dt;
  23. fscanf(input, "%d%f", &n, &dt);
  24. if ((n < 0 || n > 999) || (dt <= 0 || dt >= 0.10000)) {
  25. fprintf(output, "Invalid input\n");
  26. fclose(input);
  27. fclose(output);
  28. exit(3);
  29. }
  30. float *arr = (float *) malloc(sizeof(float) * n);
  31. for (i = 0; i < n; ++i) {
  32. arr[i] = (float) sin(dt * i);
  33. }
  34. for (i = n - 1; i >= 0; --i) {
  35. fprintf(output, "%.4f ", arr[i]);
  36. }
  37. fclose(input);
  38. fclose(output);
  39. free(arr);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement