Diagonal

Data type:

Double

Algorithm:

Basic Formula: Number of diagonal in N-gon is (N * (N-3) ) / 2.

U are given the right portion of the equation, now u have to find the value of N.

Suppose, Given value X

N = ceil ( (3 + sqrt (9 + ( 8 * N))) /2); [ceil >>> under <math.h>]

This equation comes from:

( N * ( N-3 ) ) / 2 = X

> N^{2 –} 3*N – 2*X = 0

We know, X = (– b + sqrt (b^{2} – 4 * a * c )) / 2 * a

In C/C++, u can print a double value like integer by using %0.lf.

For example, double X = 963.258;

printf(“%0.lf”, X);

output: 963

Advertisements

hmmm….should I say it? aaa whatever…keep solving problems and when you guys save the world let me know ok? A possible algorithm: how to find world peace. hmmm interesting issue, no?