Kevin321888999

Lab 4 part A

Mar 10th, 2022
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>// Standard input out put library.
  2. #include <math.h> //math library.
  3.  
  4. double pow(double num1,double num2);//Prototypes and their definitions
  5. double div(double num1, double num2){return num1/num2;}
  6. double addition(double num1, double num2){return num1+num2;}
  7.  
  8. int main(void) {
  9.   double  Term, X,power, sum1, sum2;
  10. printf("Summing 1/x^2 where X goes from 1 to 100\n");
  11.  
  12. for(int i=1; i<=100; i++){//Will loop the program for a max of 100 loops.
  13. printf("X, Term, Sum\n");
  14. printf("X= ");scanf("%lg", &X);
  15. power= pow(X,2);Term= div(1,power); //Function calls.
  16. sum1=addition(Term, sum1);//when loop comes back to this, it will take the previous Sum1 from the other loop and add it to the current Term.
  17. printf("X= %lg, Term= %lg, Sum= %lg\n",X, Term,sum1);
  18. printf("-----------------------\n");
  19.   } printf("The sum is: %lg",sum1);//After all the loops are done, this will read the sum for the last loop.
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.   return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment