Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- double f(double x, double m, double n) {
- double sum = 1;
- double tmp = 1;
- for (double i = 0; i < n; ++i) {
- tmp *= (m - i) * x / (i + 1);
- sum += tmp;
- }
- return sum;
- }
- int main(int argc, char *argv[]) {
- if(argc != 3){
- printf("Incorrect input, check README.md\n");
- return 0;
- }
- FILE *input = fopen(argv[1], "r");
- FILE *out = fopen(argv[2], "w");
- if((input == NULL) || (out == NULL)){
- printf("Incorrect file\n");
- return 0;
- }
- double x, m;
- fscanf(input, "%lf", &x);
- fscanf(input, "%lf", &m);
- if (x > 1 || x < -1) {
- printf("|x| must be less than 1\n");
- return 0;
- }
- double res = f(x, m, 50);
- fprintf(out, "Answer = %lf\n", res);
- fclose(input);
- fclose(out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement