Home > Back-end >  Function sum
Function sum

Time:06-08

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);

}
}





CodePudding user response:

The
reference 3 floor qq_44826458 response:
thank you, this is the right program and in and out of my problem is, oh

Don't know which people you answer, my test result is as the question, it is possible that your own mistakes

CodePudding user response:

The original poster described in the "layer 1" and "second" what meaning be?

CodePudding user response:

From 1 to 100 cumulative sum, expressed in function, the computer program

CodePudding user response:

Know this topic comes from which, dry narrative personally think is not a C/C + +, C/C + + personally think that there is no so-called "sub function" concept, not to mention how many straton function, all the functions in the C/C + + are parallel, there is no nested functions defined, of course, there is a C/C + + book "sub function" of the idea, but I don't want to accept,
Only personal point of view, no debate, no discussion,

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related