Monday, December 10, 2007

How to work with FUNCTION by example

How to work with FUNCTION by example

To work with FUNCTION by example

Example:

program Welcome;

const

k=' type in the number of squares to be summed ';

p=' is the sum of the first ';

var

numbertosum:integer;

answer:integer;

function sumofsquares(n: integer): integer;

var

i:integer;

sum:integer;

begin

sum:=0;

for i:=1 to n do

sum:=sum+i*i;

sumofsquares:=sum

end;

begin

Writeln(k);

readln(numbertosum);

answer:=sumofsquares(numbertosum);

Writeln(answer,p,numbertosum,' square ');

end.

No comments: