Deklarasi:
i : integer
Deskripsi menggunakan for
for i <— 0 to 10 do
if (i mod 2=1) then
write (i)
endif
endfor
gambar flowchart:
#include<iostream.h>
main() {
for (int i=0;i<=10;i++)
{
if (i%2==1)
cout <<i<<endl;
}
return 0;
}
Deskripsi menggunakan while:
i <— 1
while (i<=10) do
write (i)
i <— i+2
endwhile
gambar flowchartnya:
#include<iostream.h>
main(){
int i=1;
while (i<=10)
{
if (i%2==1)
cout <<1<<endl;
}
return 0;
}
Deskripsi menggunakan do-while:
i <— 1
repeat
write(i)
i<— i+2
until (1>10)
gambar flowchartnya:
#include<iostream.h>main() {
int i=1;
do {
if (i%2==1)
cout<<i<<endl;
i++;
} while (i<=10);
return 0;
}
Tidak ada komentar:
Posting Komentar