Kamis, 06 Februari 2014

Membuat Program Sederhana Menggunakan Fungsi NEST FOR Pada Netbeans

1. Buatlah Program berikut ini

#include <iostream.h>
#include <conio.h>
main()
{
int N,Max;
clrscr();
cout<<"Masukkan Bilangan Terbesar ";cin>>Max;
for (N=1;N<=Max;N++)
{
cout<<N<<"\t";
}
getch();
}
HASIL
Masukkan Bilangan Terbesar 7
1 2 3 4 5 6 7

2. Buatlah Program berikut ini

#include <iostream.h>
#include <conio.h>
main()
{
int X,Y;
clrscr();
for (X=1;X<=5;X++)
{
for (Y=1;Y<=3;Y++)
{
cout<<X<<"\t";
}
cout<<"\n";
}
cout<<"\n\n\n";
for (X=1;X<=5;X++)
{
for (Y=1;Y<=3;Y++)
{
cout<<Y<<"\t";
}
cout<<"\n";
}
getch();
}
HASIL
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3

3. Buatlah Program berikut ini

#include <iostream.h>
#include <conio.h>
main()
{
int X,Y;
clrscr();
for (X=1;X<=5;X++)
{
for (Y=1;Y<=X;Y++)
{
cout<<Y<<"\t";
}
cout<<"\n";
}
getch();
}
HASIL
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

4. Ubahlah perintah berikut

cout<<Y<<"\t";
Menjadi
cout<<X<<"\t";
HASIL
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Tidak ada komentar:

Posting Komentar