0% found this document useful (0 votes)
68 views9 pages

Perulangan: Int I For (I 0 I 3 I++) Cout I Hasilnya I 0 0 3, 0+1 1 I 1 1 3, 1+1 2

The document discusses for loops in C++ for printing values in ascending and descending order. It provides examples of using for loops to print number sequences based on user input for the number of terms. This includes examples to print a range of numbers, numbers separated by commas, and the sum of a number series.

Uploaded by

Sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views9 pages

Perulangan: Int I For (I 0 I 3 I++) Cout I Hasilnya I 0 0 3, 0+1 1 I 1 1 3, 1+1 2

The document discusses for loops in C++ for printing values in ascending and descending order. It provides examples of using for loops to print number sequences based on user input for the number of terms. This includes examples to print a range of numbers, numbers separated by commas, and the sum of a number series.

Uploaded by

Sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

PERULANGAN

int i;
for(i=0; i<=3; i++)
cout<<i;

hasilnya
i=00<=3 cetak 0 ,0+1=1
i=11<=3 cetak 1,1+1=2
i=22<=3 cetak 2,2+1=3
i=33<=3 cetak 3,3+1=4
i=44<=3 stop

int i;
for(i=4; i>=0; i--)
cout<<i<<” “;
hasilnya
i=44>=0 cetak 4 ,4-1=3
i=33>=0 cetak 3 ,3-1=2
i=22>=0 cetak 2 ,2-1=1
i=11>=0 cetak 1 ,1-1=0
i=00>=0 cetak 0 ,0-1=-1
i=-1-1>=0 stop
Perulangan Menaik dengan input
int i, deret;
cout<<”Masukan Jumlah deret = “;
cin>>deret;
for(i=0; i<=deret; i++)
cout<<i<<” “;
Perulangan Menurun dngan input
{int i, input;
cout<<”Masukan Jumlah deret = “;
cin>>input;
for(i=input; i>=0; i--)
cout<<i<<” “;
}
int i, baris;
cout<<"Masukan Jumlah baris = ";
cin>>baris; mis input = 3
for(i=1; i<baris; i++)
cout<<i<<", ";
cout<<i<<".";
hasil nya

1, 2, 3.
int i, baris, k;
k=0;
cout<<"Masukan Jumlah baris = ";
cin>>baris; mis input = 4
for(i=1; i<baris; i++)
{cout<<i<<", ";
k = k+1;}
cout<<i<<". "<<k;
hasil nya

1, 2, 3, 4.3
Buatlah program agar menghasilkan
perhitungan deret sebagai berikut:
1 + 2 + 3 + 4 =10
Koding seperti diatas, tapi dirubah
rumus untuk K
Input Rumus k Hasil
input = 1  K=1 1=1
input = 2  K=3  1+ 2 = 3
input = 3  K=6  1+ 2 + 3 = 6
input = 4  K = 10  1+ 2 + 3 + 4 = 10
input = 5  K = 15  1+ 2 + 3 + 4 + 5 = 15
int i, baris, k;
k=0;
cout<<"Masukan Jumlah baris = ";
cin>>baris; mis input = 4
for(i=1; i<baris; i++)
{cout<<i<<" + ";
k = k+i;}
cout<<i<<" = "<<k+i;
hasilnya: 1 + 2 + 3 + 4 = 10

You might also like