DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

IntervalProba.pas

11.07.2010
| 589 views |
  • submit to reddit
        // gives the 90, 95 98, 99 and 99.9% trust interval for probability distribution (you enter n and p). This small program is in pascal.
//
program IntervalProba;

(* gives the 90, 95 98, 99 and 999% trust interval for probability distro *)

const
    a = 1.64;  (* ->90% *)
    b = 1.96;  (* ->95% *)
    c = 2.33;  (* ->98% *)
    d = 2.575; (* ->99% *)
    e = 3.29;  (* ->99.9% *)

var
    p : real;        (* observed probability *)
    n : integer;     (* sample *)
    number1 : real;
    number2 : real;
    k : real;

begin
    writeln('Enter p and n, please : ');
    readln (p, n);
    k := sqrt(p * (1 - p) / n);
    number1 := p - a * k;
    number2 := p + a * k;
    writeln('90% -> ', '[', number1, ' & ', number2, ']'); 
    number1 := p - b * k;
    number2 := p + b * k;
    writeln('95% -> ', '[', number1, ' & ', number2, ']'); 
    number1 := p - c * k;
    number2 := p + c * k;
    writeln('98% -> ', '[', number1, ' & ', number2, ']'); 
    number1 := p - d * k;
    number2 := p + d * k;
    writeln('99% -> ', '[', number1, ' & ', number2, ']'); 
    number1 := p - e * k;
    number2 := p + e * k;
    writeln('99.9% -> ', '[', number1, ' & ', number2, ']'); 
end.