Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>// Standard input out put library.
- #include <math.h> //math library.
- double pow(double num1,double num2);//Prototypes and their definitions
- double div(double num1, double num2){return num1/num2;}
- double addition(double num1, double num2){return num1+num2;}
- int main(void) {
- double Term, X,power, sum1, sum2;
- printf("Summing 1/x^2 where X goes from 1 to 100\n");
- for(int i=1; i<=100; i++){//Will loop the program for a max of 100 loops.
- printf("X, Term, Sum\n");
- printf("X= ");scanf("%lg", &X);
- power= pow(X,2);Term= div(1,power); //Function calls.
- 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.
- printf("X= %lg, Term= %lg, Sum= %lg\n",X, Term,sum1);
- printf("-----------------------\n");
- } printf("The sum is: %lg",sum1);//After all the loops are done, this will read the sum for the last loop.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment