Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main()
- {
- FILE *input = fopen("input.txt", "r");
- FILE *output = fopen("output.txt", "w");
- if (!input) {
- printf("File input not found\n");
- fclose(input);
- fclose(output);
- exit(1);
- }
- if (!output) {
- printf("Can't create output file\n");
- fclose(input);
- fclose(output);
- exit(2);
- }
- int n, i;
- float dt;
- fscanf(input, "%d%f", &n, &dt);
- if ((n < 0 || n > 999) || (dt <= 0 || dt >= 0.10000)) {
- fprintf(output, "Invalid input\n");
- fclose(input);
- fclose(output);
- exit(3);
- }
- float *arr = (float *) malloc(sizeof(float) * n);
- for (i = 0; i < n; ++i) {
- arr[i] = (float) sin(dt * i);
- }
- for (i = n - 1; i >= 0; --i) {
- fprintf(output, "%.4f ", arr[i]);
- }
- fclose(input);
- fclose(output);
- free(arr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement