← Back to topics
Topic

n-polygon

D
Diabolic
I am 100% sure that my task is correct. What is the problem?

http://www.z-trening.com/new/www/html/submit.php?submit=7100044111&subm_code=1

Thanks in advance.
o
ortschun
Try using pi = 3.1415926535897932
N
Nikola94
you don't have to do that. pi is already defined in pascal so you don't need to define it as a constant
v
vasja
Can you tell me what formulas to use for area?

I used : A = (n*r*r* Sin(360/pi ) )/2 , the result from sin function converted to degrees, but i get wrong result ,very wrong:D HELP...
N
Nikola94
i used A = n*r*r*sin(pi/n)*cos(pi/n) and it works
D
Diabolic
Thanks for the posts. I tried everything and again I got all wrong results. What is the problem?
N
Nikola94
i saw your code and the mistake is that you must use writeln for both area and perimeter. You can't use write. put writeln and test it.
N
Nikola94
@diabolic

and 1 more thing. put longint instead of integer
D
Diabolic
Thank you very much for the tip. Now it works. But why longint, when it wasn't needed ? Is there any evaluator issue?
N
Nikola94
i thought longint was needed because n <= 100000 but integer range is [-32768..32767] so i have put longint immediately
N
Nocturne
@vasja
A = N*R*R*SIN(2*PI/N)/2
We divide the polygon in N triangles each with an area equal to half of the area of a parallelograme (rhombus) with side R and angle 360/N (2*PI/N) between the sides. Therefore, the area of one triangle is P=R*R*SIN(2*PI/N)/2 and the total area equals N times the area P because all the triangles are congruent.
m
matteo123
and I have some problems with that task 0/10
here is my code:

program polygon;
var n:longint;
r,a,p:real;
begin
readln (n,r);
a:=n*r*r*sin(2*pi/n)/2;
p:=r*r*sin(2*pi/n)/2;
writeln (p :6:5);
writeln (a :6:5);
readln;
end.
n
nikola
If you look better you will see that your A and P are the same except A is n times bigger than P.
You have a:=n*r*r*sin(2*pi/n)/2;
and that is your area, and that's good. But your perimeter is not good. Try to think how can you calculate perimeter. You have got R, and you have N, so if you split the N-polygon in N equal triangles, you will get a triangle with angle 2Pi/N and two side chains with length R, and the third one is the one you need to calculate perimeter. How to find the third one??? Use cosinus theorem and you can find the third side chain of triangle. Now that you have that length, just multiply it with N cuz you have N lengths and you get your perimeter.
s
s-lime
This task is purely mathematical, runs O(1). :P
m
matteo123
I am not good at trigonometry
g
gates
you don't need to be good at trigonometry to solve this problem..you need just basics of trigonometry
h
halil
Mateo,
Parimeter = 2*n*r*sin(Pi/n)
Area = n*r*r*sin(Pi/n)*cos(Pi/n)
I'm hoping that I didn't make any mistake.
d
dancsi
I always get the wrong result when I upload my task :( ... Here is the code:
#include <iostream>
#include <math.h>
#define PI 3.141592653589793
using namespace std;

int main()
{
double n, r, p, o, sin1, sin2;
scanf("%lf%lf", &n, &r);
sin1=2*PI/n;
sin2=PI/n;
p=n*r*r/2*sin(sin1);
o=2*n*r*sin(sin2);
printf("%.5lf\n%.5lf", o, p);
return 0;
}
m
matteo123
use this
Parimeter = 2*n*r*sin(Pi/n)
Area = n*r*r*sin(Pi/n)*cos(Pi/n)