|
|
вернуться в форумMuch bigger C code but efficient I guess(Execution time:0.015sec;Memory:140 kB) I have written the code the using user defined function thats why it has become much bigger. #include<Stdio.h> #include<math.h> int Sn(int n); int An(int a); int main() { int x; scanf("%d",&x); Sn(x); } int Sn(int n) { int j; if(n==1) {An(1); printf("+1");} else { for(j=1;j<n;j++) printf("("); for(j=1;j<=n;j++) {if(j==1) {An(j);printf("+%d)",n);} else if(j!=n) {An(j);printf("+%d)",n-j+1);} else {An(j);printf("+1");}}} } int An(int a) { int i,p; if(a==1) printf("sin(%d)",a); else {for(i=1;i<=a;i++) { p= pow(-1,i+1); if(i==1) printf("sin(%d",i); else if(p==1) printf("+sin(%d",i); else printf("-sin(%d",i);} for(i=0;i<a;i++) printf(")"); } } Edited by author 29.10.2020 21:19 |
|
|