10432  Polygon Inside A Circle
Moderator: Board moderators
10432  Polygon Inside A Circle
What's wrong with my code ?
[c]
#include <stdio.h>
#include <math.h>
#define Pi 3.1415926535897932384626433832795029L
int main()
{
long double ang;
int r, n;
while(scanf("%d %d",&r,&n)==2)
{
ang = 180  ((double)180*(n2)/n);
printf("%.3lf\n",(sin(Pi/180*ang)*r*r*n)/2);
}
return 0;
}
[/c]
Can you see ? Thanks, Aur
[c]
#include <stdio.h>
#include <math.h>
#define Pi 3.1415926535897932384626433832795029L
int main()
{
long double ang;
int r, n;
while(scanf("%d %d",&r,&n)==2)
{
ang = 180  ((double)180*(n2)/n);
printf("%.3lf\n",(sin(Pi/180*ang)*r*r*n)/2);
}
return 0;
}
[/c]
Can you see ? Thanks, Aur

 Guru
 Posts: 834
 Joined: Wed May 29, 2002 4:11 pm
 Location: Wroclaw, Poland
 Contact:
Code: Select all
(sin(Pi/180*ang)*r*r*n)/2
Code: Select all
(sin(Pi/180*ang)*r*r*n)/2.0
Code: Select all
sin(acos(1.0)*2.0/n)
Dominik Michniewski
10432 wa????
Can any one tell me why i am getting wrong answer with the following code????????
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
double r,n,ac,p,pi,t,q;
while(scanf("%lf%lf",&r,&n)==2)
{
pi=2*acos(0);
ac=pi*r*r;
p=2*pi*r;
p/=n;
t=0.5*r*r*pi/n;
q=(0.5*r*r*sin(pi/n));
t=q;
ac=t*n;
printf("%.3lf\n",ac);
}
}
The reason is probably due to precision errors when n is large. What happens then is that t becomes so small in comparison to ac so that subtracting t*n from ac will have no effect. Anyway, there's a simpler solution to this problem, and you have the answer (almost) somewhere in your code, but I'll leave it to you to sort out what you need :)
Best Regards
Best Regards
10432
I got WA and i figured out that it should be caused by some precision error while I was defining the value of Pi.
I am using pascal to write the program and the built in sine function requires a radian value instead of degree. So I have to convert it back to radian first and therefore I requires Pi. Is there anyways to define the exact value of Pi? (or perhaps, at least it's precious enough for me to get an AC)
Thx! Sorry for my poor English.
I am using pascal to write the program and the built in sine function requires a radian value instead of degree. So I have to convert it back to radian first and therefore I requires Pi. Is there anyways to define the exact value of Pi? (or perhaps, at least it's precious enough for me to get an AC)
Thx! Sorry for my poor English.
The value of pi defined in the system unit is more than enough.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org

 Experienced poster
 Posts: 136
 Joined: Tue Apr 01, 2003 6:59 am
 Location: Jakarta, Indonesia
10432  Angle conversion
Can anybody tell me how to convert angle in degree to angle in radians ?
For example if the angle is 60 degree, what would it be in radians? Please show me the proccess of the conversion.
Thanx in advance.
For example if the angle is 60 degree, what would it be in radians? Please show me the proccess of the conversion.
Thanx in advance.
That's not hard.
First you need to know that pi rad = 180 degrees
Thus 1 degree = pi / 180 radians, or n degrees = n * pi / 180 rad.
e.g. 60 degrees = 60 * pi / 180 = pi / 3 rad.
Hope this helps!
First you need to know that pi rad = 180 degrees
Thus 1 degree = pi / 180 radians, or n degrees = n * pi / 180 rad.
e.g. 60 degrees = 60 * pi / 180 = pi / 3 rad.
Hope this helps!
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org