Contoh Program C++ menggunakan FOR
#include <iostream.h>
#include <stdlib.h>
void main ()
{
int x,c,d,n;
char ask;
atas:
cout<<"Pilihan Jenis Program 1-4 :";cin>>x;
cout<<"Masukan Jumlah Baris :";cin>>n;
cout<<endl;
if(x==1)//Program 1
{
for (c=1;c<=n;c++)
{
for (d=0;d<c;d++)
{
cout<<"*";
}
cout<<endl;
}
cout<<"Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y') || (ask=='Y'))
{ system("CLS");
goto atas; }
}
else
if (x==2) //program 2
{
for (c=0;c<=n;c++)
{
for (d=n;d>c;d--)
{
cout<<"*";
}
cout<<endl;
}
cout<<"Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y')||(ask=='Y'))
{ system("CLS");
goto atas; }
}
else
if (x==3) //program 3
{
for (c=0;c<=n;c++)
{
for (d=0;d<c;d++)
{
cout<<" ";
}
for (d=n;d>c;d--)
{
cout<<"*";
}
cout<<endl;
}
cout<<"Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y')||(ask=='Y'))
{ system("CLS");
goto atas; }
}
else
if (x==4) //program 4
{
for (c=0;c<=n;c++)
{
for (d=n-1;d>c;d--)
{
cout<<" ";
}
for (d=0;d<=c;d++)
{
cout<<"*";
}
cout<<endl;
}
cout<<"Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y') || (ask=='Y'))
{ system("CLS");
goto atas; }
}
else
{ cout<<"Pilihan Tidak Tersedia !!"<<endl;
cout<<"Coba Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y') || (ask=='Y'))
{ system("CLS");
goto atas; }
}
cout<<"Terima Kasih"<<endl;
}
#include <stdlib.h>
void main ()
{
int x,c,d,n;
char ask;
atas:
cout<<"Pilihan Jenis Program 1-4 :";cin>>x;
cout<<"Masukan Jumlah Baris :";cin>>n;
cout<<endl;
if(x==1)//Program 1
{
for (c=1;c<=n;c++)
{
for (d=0;d<c;d++)
{
cout<<"*";
}
cout<<endl;
}
cout<<"Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y') || (ask=='Y'))
{ system("CLS");
goto atas; }
}
else
if (x==2) //program 2
{
for (c=0;c<=n;c++)
{
for (d=n;d>c;d--)
{
cout<<"*";
}
cout<<endl;
}
cout<<"Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y')||(ask=='Y'))
{ system("CLS");
goto atas; }
}
else
if (x==3) //program 3
{
for (c=0;c<=n;c++)
{
for (d=0;d<c;d++)
{
cout<<" ";
}
for (d=n;d>c;d--)
{
cout<<"*";
}
cout<<endl;
}
cout<<"Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y')||(ask=='Y'))
{ system("CLS");
goto atas; }
}
else
if (x==4) //program 4
{
for (c=0;c<=n;c++)
{
for (d=n-1;d>c;d--)
{
cout<<" ";
}
for (d=0;d<=c;d++)
{
cout<<"*";
}
cout<<endl;
}
cout<<"Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y') || (ask=='Y'))
{ system("CLS");
goto atas; }
}
else
{ cout<<"Pilihan Tidak Tersedia !!"<<endl;
cout<<"Coba Lagi ? [Y/T] ";cin>>ask;
if ((ask=='y') || (ask=='Y'))
{ system("CLS");
goto atas; }
}
cout<<"Terima Kasih"<<endl;
}
#include
ReplyDeletevoid main()
{
cout<<"TERIMA KASIH ATAS INFONYA GAN"<<endl;
}
sama2 sob, makasih dah mampir...
Deletebuat contoh yang lain lagi dnk,! switch,pointer, dan lain2
ReplyDeletePada kesempatan lain y sob..
Delete