Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. int main(int argc, char* argv[]) {
  6.     if (argc != 3) {
  7.         printf("Usage: exp <start> <end>\n");
  8.         return 1;
  9.     }
  10.  
  11.     int start = atoi(argv[1]);
  12.     int end = atoi(argv[2]);
  13.  
  14.     if (start > end) {
  15.         printf("The start value must be lower than the end value");
  16.         return 1;
  17.     }
  18.  
  19.     // On lance pari GP
  20.     FILE* gp;
  21.     char path[1035];
  22.     gp = popen("echo 'forstep(i=0, 2, 0.1, print(exp(i)))\nquit\n' | /usr/bin/gp -q", "r");
  23.     if (gp == NULL) {
  24.         printf("GP n'est pas installé sur la machine\n");
  25.         exit(1);
  26.     }
  27.  
  28.     long double i = 0;
  29.     while (fgets(path, sizeof(path)-1, gp) != NULL) {
  30.         long double n = exp(i);
  31.         printf("GP = %s", path);
  32.         printf("C  = %.20Lf\n", n);
  33.         i += 0.1;
  34.     }
  35.     // printf("%s\n", system("\\p 128\nforstep(i=1, 1000, 0.1, print(i \"=\"  ${fn}(i)))\nquit\n"));
  36.  
  37.     pclose(gp);
  38.  
  39. /*
  40.     for (double i = (double)start ; i <= end ; i++) {
  41.         printf("exp(%d)=%d", i, exp(i));
  42.     }*/
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement