Kevin321888999

For loop excersise

Mar 24th, 2022
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>//standard input output library
  2. #include <math.h>//standard math library
  3. double summing(double num1 ){return  pow((3* num1)+1,.5);}//The prototype, function, and function defninition of the equation given.
  4. double addition(double num1, double num2){
  5.   return num1+num2;}//addition prototype
  6.  
  7. int main(void) {
  8. double sum;
  9. double term;
  10.  
  11.  
  12. for(double x=0;x<1000;x+=2){//will loop automatically. Starts off at X=0 but increments by 2.
  13. term=summing(x);// This will take the X values and plug it into the summing equation.
  14. sum= addition(term, sum);// This will take the previous sum, add it to the new term, and create the new sum for the new loop.
  15. printf("x= %lg||term= %lg||sum= %lg",x,term,sum);
  16. printf("\n--------------------------------------------------\n");
  17. }
  18.   return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment