Advertisement
_takumi

ram.c

Nov 27th, 2022 (edited)
1,961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. double f(double x, double m, double n) {
  5.     double sum = 1;
  6.     double tmp = 1;
  7.     for (double i = 0; i < n; ++i) {
  8.         tmp *= (m - i) * x / (i + 1);
  9.         sum += tmp;
  10.     }
  11.     return sum;
  12. }
  13.  
  14. int main(int argc, char *argv[]) {
  15.     if(argc != 3){
  16.         printf("Incorrect input, check README.md\n");
  17.         return 0;
  18.     }
  19.     FILE *input = fopen(argv[1], "r");
  20.     FILE *out = fopen(argv[2], "w");
  21.     if((input == NULL) || (out == NULL)){
  22.         printf("Incorrect file\n");
  23.         return 0;
  24.     }
  25.     double x, m;
  26.     fscanf(input, "%lf", &x);
  27.     fscanf(input, "%lf", &m);
  28.     if (x > 1 || x < -1) {
  29.         printf("|x| must be less than 1\n");
  30.         return 0;
  31.     }
  32.     double res = f(x, m, 50);
  33.     fprintf(out, "Answer = %lf\n", res);
  34.     fclose(input);
  35.     fclose(out);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement