Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Pascal Programming Help w/ loops

funshinefunshine Member Posts: 3
1.Write a program that reads a real value X
and a positive integer N and then
calculates and prints the value X^N .

2. write a program that reads a positive
integer and then find s the smallest
power of two greater than or equal
to the number that was read.

Comments

  • ActorActor Member Posts: 447 ✭✭
    : 1.Write a program that reads a real value X
    : and a positive integer N and then
    : calculates and prints the value X^N .
    [code]
    Program XtotheN ;
    Var
    Product, x : Real ;
    i,n : Integer ;

    begin
    Write('Enter a real number ') ;
    ReadLn (x) ;
    Write('Enter an integer ') ;
    ReadLn (n) ;

    Product := 1 ;
    for i := 1 to n do
    Product := Product * x ;

    WriteLn (x:0, '^', n:0, '=', Prod:0)
    end.
    [/code]
    :
    : 2. write a program that reads a positive
    : integer and then find s the smallest
    : power of two greater than or equal
    : to the number that was read.
    :
    [code]
    Program PwrOf2 ;
    Var
    n, Pwr : Word ;

    begin
    Write ('Enter a positive integer ') ;
    ReadLn (n) ;

    Pwr = 1 ;
    while Pwr < n do
    Pwr := 2 * Pwr ;

    WriteLn ('The smallest power of two that is greater than or equal to ',
    n:0, ' is ', Pwr:0)
    end.
    [/code]
Sign In or Register to comment.