This is a collection of some examples of programs that implement looping in C + +, I hope the program - this program can be useful.
The first program.
#include <iostream.h>//header
#include <stdlib.h>
#include <conio.h>
void main()//fungsi utama
{//pembuka program
cout<<"|======================================================|\n";//MENAMPILKAN TULISAN KE LAYAR
cout<<"| PROGRAM PERULANGAN FOR |\n";
cout<<"|======================================================|\n";
int a, b, c, baris;//variabel bertipe bilangan bulat
back:
cout<<" Masukkan Banyaknya Bilangan : ";
cin>>baris;
cout<<" ---------------------------------------\n";
for(c=baris; c>0; c-=2)
{
for (a=1;a<=baris;a+=2)
{cout<<" "<<a<<" ";}//pernyataan dalam for
cout<<endl;
for (b=2;b<=baris;b+=2)
{cout<<" "<<b;}
cout<<endl;
}
getch();
system("cls");
goto back;
}//penutup program
The second program.
#include <iostream.h>//header
#include <conio.h>
void main()//fungsi utama
{//pembuka program
int a,pil;
cout<<"|======================================================|\n";
cout<<"| PROGRAM BILANGAN GANJIL / GENAP |\n";
cout<<"|======================================================|\n";
cout<<" 1. GANJIL\n";
cout<<" 2. GENAP\n";
awal:
cout<<" Masukkan Pilihan : "; cin>>pil;
cout<<" ----------------------------------\n";
if (pil == 1)//penggunaan if
{
for(a=1;a<150;a+=2)//perulangan
{
cout<<" "<<a<<endl;//pernyataan
}
}
else
if (pil == 2)
{
for(a=2;a<150;a+=2)
{
cout<<" "<<a<<endl;
}
}
else
{
cout<<" Pilihan yang Anda Masukkan Salah\n";
goto awal;
}
getch();
}//penutup program
Tidak ada komentar:
Posting Komentar