Dalam Bahasa Pascal:
uses crt;
Var
x:Integer;
Y:Integer;
Z:Integer;
Begin
CLRSCR;
WRITELN('Masukan Angka: ');READLN(x);
Z:=0;
For y := 1 to x do
Begin
If Y Mod 2= 0 Then
Z:=Z-Y
Else
Z:=Z+Y;
If Y <> x then
Begin
If Y mod 2 = 0 Then
WRITE(Y,'+')
Else
WRITE(Y,'-');
End
Else
WRITE(Y);
END;
WRITELN();
WRITELN('Jumlah Deret: ',Z);
READLN();
END.
Dalam Bahasa Algoritma:
Var
x:Integer
Y:Integer
Z:Integer
Begin
CLRSCR;
Output('Masukan Angka: ')Input(x)
Z-->0
For y -->1 to x do
Begin
If Y Mod 2= 0 Then
Z-->Z-Y
Else
Z-->Z+Y
If Y <> x then
Begin
If Y mod 2 = 0 Then
Output(Y,'+')
Else
Output(Y,'-')
End
Else
Output(Y)
END
Output()
Output('Jumlah Deret: ',Z)
END Algoritma
Var
x:Integer;
Y:Integer;
Z:Integer;
Begin
CLRSCR;
WRITELN('Masukan Angka: ');READLN(x);
Z:=0;
For y := 1 to x do
Begin
If Y Mod 2= 0 Then
Z:=Z-Y
Else
Z:=Z+Y;
If Y <> x then
Begin
If Y mod 2 = 0 Then
WRITE(Y,'+')
Else
WRITE(Y,'-');
End
Else
WRITE(Y);
END;
WRITELN();
WRITELN('Jumlah Deret: ',Z);
READLN();
END.
Dalam Bahasa Algoritma:
Var
x:Integer
Y:Integer
Z:Integer
Begin
CLRSCR;
Output('Masukan Angka: ')Input(x)
Z-->0
For y -->1 to x do
Begin
If Y Mod 2= 0 Then
Z-->Z-Y
Else
Z-->Z+Y
If Y <> x then
Begin
If Y mod 2 = 0 Then
Output(Y,'+')
Else
Output(Y,'-')
End
Else
Output(Y)
END
Output()
Output('Jumlah Deret: ',Z)
END Algoritma
Tidak ada komentar:
Posting Komentar