ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1149. Sinus Dances

Much bigger C code but efficient I guess(Execution time:0.015sec;Memory:140 kB)
Posted by Fahim shahriyar 29 Oct 2020 21:18
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