1, write a program to achieve the following functions: in the main function of the input integer x, write two straton function calculation 1 1/3 + +. 1/5-1/7. Add x sum, before the first layer, the second division, requirements shall not be used library function is complete, and will result in the main function of the output
CodePudding user response:
# include "stdio.h" Int main (void) { Int x=0, I=0, flag=1; Double sum=0; The scanf (" % d ", & amp; X); For (I=1; i<=x; I++) { The sum +=flag * (1.0/(2 * I - 1)); Flag=- flag; } Printf (" % g ", sum); return 0; }
CodePudding user response:
# include & lt; stdio.h> Double div (int I) { The return of 1.0/(2 * I - 1); } Double the total (int n) { Double sum=0; Int sign=1; For (int I=1; i <=n; I++, sign *=1) { The sum +=div (I) * sign; }//end for return sum; } The main () { Int x=100; Double the result; Result=total (x); Printf (" % lf \ n ", result); }
CodePudding user response:
Thank you, this is the right program and in and out of my problem is, oh
CodePudding user response:
#include Float addition (int x); Float division (int I); Int main (int arg c, char * argv []) { int num; Printf (" please enter an integer: \ r \ n "); The scanf (" % d ", & amp; Num); Printf (" % f \ r \ n ", addition (num)); Getchar (); return 0; } Float addition (int x) { int i; Float sum=0.0; For (I=1; i <=x; I +=2) { The sum +=division (I); Printf (" sum=% f \ n ", sum); } return sum; } Float division (int I) { The static x=1; If (x==1) { x=0; 1.0/I return; } The else { X=1; The return - (1.0/I);