Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. double height(int argc, char *argv[], int j, double temp, double recHeight, double midRec) {
  7. double end = atof(argv[2]);
  8. double incNum = atof(argv[3]);
  9. double low = atof(argv[4]);
  10. double high = atof(argv[5]);
  11. double numArgs = argc - 7;
  12.  
  13. if (j > numArgs) return 0;
  14.  
  15. recHeight = atof(argv[j+6]) * pow(midRec,temp);
  16.  
  17. return recHeight + height(argc, argv, j + 1, temp - 1, recHeight, midRec);
  18. }
  19.  
  20. double sum(int argc, char *argv[], double width, double recArea, int i, double N) {
  21. double end = atof(argv[2]);
  22. double incNum = atof(argv[3]);
  23. double low = atof(argv[4]);
  24. double high = atof(argv[5]);
  25. double numArgs = argc - 7;
  26.  
  27. if (i > N) return 0;
  28.  
  29. double leftEdge = (low + ((i-1) * width));
  30. double rightEdge = (low + i*width);
  31. double midRec = (leftEdge + rightEdge)/2.0;
  32. double recHeight = 0.0;
  33. double temp = numArgs;
  34. int j = 0;
  35. recHeight = height(argc, argv, j, temp, recHeight, midRec);
  36.  
  37. recArea = recHeight * width;
  38. return recArea + sum(argc, argv, width, recArea, i + 1, N);
  39. }
  40.  
  41. double incFunc(double N, int argc, char *argv[]) {
  42. double end = atof(argv[2]);
  43. double incNum = atof(argv[3]);
  44. double low = atof(argv[4]);
  45. double high = atof(argv[5]);
  46. double numArgs = argc - 7;
  47.  
  48. if (N > end) return 0;
  49.  
  50. double width = (high - low)/N;
  51. double recArea = 0.0;
  52. int i = 0;
  53. recArea = sum(argc, argv, width, recArea, i, N);
  54.  
  55. printf("%lf\t %lf\n", N, recArea);
  56. return N + incFunc(N + incNum, argc, argv);
  57. }
  58.  
  59.  
  60. int main(int argc, char *argv[]){
  61. double N = atof(argv[1]);
  62.  
  63. incFunc(N, argc, argv);
  64.  
  65. /*
  66. for(int j = 0; j <= numArgs; j++){
  67. recHeight = ((atof(argv[j+6]) * pow(midRec,temp)) + recHeight);
  68. temp--;
  69. }
  70.  
  71. recArea = (recArea + (recHeight * width));
  72. }
  73. */
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement