Senin, 04 April 2011

The algorithm calculates the number of rows of 1 +2 +3 +....+ n (Algoritma menghitung jumlah deret 1+2+3+....+n)

The algorithm calculates the number of rows of 1 +2 +3 +....+ n
With loop for:

# algorithmic
{summing the series 1 +2 +3 +...+ n, where n is a positive integer. The value n read terlabih first.}

# Declaration
n: integer
i: integer
number: integer

# Algorithm
read (n);
number <= 0; {initialize number of runs with 0}
for <= 1 to n; {repeat the summation of series with a lot of n times}
    number <= sum + i
endfor
write (amount)

Progam with pascal:
(* Declaration: *)
var
n: integer;
i: integer
number: integer

(* Algorithm: *)
begin
write ('How many n'); readln; {many tribes series}
number: = 0; {initialize number of runs with 0}
for i: = 1 to n
    begin
      total: = total + i;
    end; {for}
writeln ('number of rows =', number);

Program with C:
# include (stdio.h)
main ()
{
/ * Declaration * /
int m;
int i;
int count;

/ * Algorithm * /
prinf ("How many n?"); scant ("% d", & n); {a lot of spare rows}
number = 0; {initialize number of runs with 0}
for (i = 1; i <= n; i + +)
{
total = total + i;
}
printf ("number of rows =% d \ n", amount);
}

Tidak ada komentar:

Posting Komentar