Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- float der(int,int);
- int derx(int,int);
- main(){
- cout<<der(5,1)<<endl;
- cout<<derx(5,1);
- }
- float der(int n,int c){
- char k;
- if(!n){
- return 0;
- }
- int x;
- if(n%4==0){
- x=1;
- }else{
- x= -1;
- }
- if(c%4==0){
- k='+';
- }
- else{
- k='-';
- }
- cout<<k<<1<<"/"<<(2*(c));
- if(n==1)
- cout<<endl<<"S: ";
- return 1/(2.0*n*x)+der(n-1,c+1);
- }
- int derx(int n,int c){
- int x;
- char y;
- if(!n){
- cout<<endl<<"S =";
- return 0;
- }
- if(n%2==0){
- x=-1;
- }else{
- x= 1;
- }
- y= x==1 ? '\0': c%1==0 ? '+' : '-';
- cout<<x*(1+(c-1)*2)<<y;
- return x*(1+(n-1)*2)+derx(n-1,c+1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement