Sunday, August 17, 2014

uva : 356 - Square Pegs And Round Holes


#include<stdio.h>
#include<math.h>
int main()
{
    int n,m=-2;
    while(scanf("%d",&n)==1)
    {
        if(m>-1)printf("\n");
        m=n;
        if(m==0){
        printf("In the case n = 0, 0 cells contain segments of the circle.\nThere are 0 cells completely contained in the circle.\n");
        continue;
        }
        n=2*n-1;
        int sum=0,i,j,k,l,x,com=0,y;
        float rad;
        rad=(float)n/2;
      for(x=1;x<rad;x++)
       {
           y = (int)sqrt(rad*rad-x*x);
          com+=y;
       }
        printf("In the case n = %d, %d cells contain segments of the circle.\nThere are %d cells completely contained in the circle.\n",m,n*4,com*4);
    }
    return 0;
}

No comments:

Post a Comment