|
|
back to boardwhat is wa 3? here is my code! Posted by john 23 Jun 2019 02:44 #include<iostream> using namespace std; void sin (int n,int i) { if(i==n+1) return ; else { if(i==1) { cout<<"sin("<<i; sin(n,i+1); } else if(i%2==1) { cout<<"+sin("<<i; sin(n,i+1); } else { cout<<"-sin("<<i; sin(n,i+1); } cout<<")"; } } void sol( int n,int i) { if(i==n) return; if(i==1) for(int i=1;i<n;i++) cout<<'('; sin(i,1); cout<<'+'<<n-i+1<<')'; sol(n,i+1); if(i==1) { sin(n,1); cout<<"+1"; } } int main () { int n; cin>>n; sol(n,1); } |
|
|