Advertisement
Guest User

Untitled

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