Program C++ Menggunakan For
#include<iostream.h>
#include<stdlib.h>
void main()
{
int x,a,c,d,b,n,e,f,pilih;
char ask;
atas:
cout<<" Menu Utama\n";
cout<<"===================\n";
cout<<"| 1. Program |\n";
cout<<"| 0. Selesai |\n";
cout<<"===================\n\n";
cout<<"Pilih Menu : ";cin>>pilih;
if(pilih==1)
{
system("CLS");
goto pilih;
}
else
exit (0);
pilih:
cout<<"Pilih Jenis Program 1-5:";cin>>x;
cout<<"Masukan Jumlah Baris :";cin>>n;
cout<<endl;
b=1;
c=1;
d=2;
e=4;
f=7;
if(x==1) //program 1
{
for(a=1;b<=n;b++)
{
cout<<" "<<a;
a=a+c;
c=c+d;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
else
if(x==2) //program 2
{
for(a=3;b<=n;b++)
{
cout<<" "<<a;
a=a*2;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
else
if(x==3) //program 3
{
for(a=2;b<=n;b++)
{
cout<<" "<<a;
a=a+e;
e=e+d;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
else
if(x==4) //program 4
{
for(a=1;b<=n;b++)
{
cout<<" "<<a;
a=a+3;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
else
if(x==5) //program 5
{
for(a=9;b<=n;b=b++)
{
cout<<" "<<a;
a=a+f;
f=f+2;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
}
#include<stdlib.h>
void main()
{
int x,a,c,d,b,n,e,f,pilih;
char ask;
atas:
cout<<" Menu Utama\n";
cout<<"===================\n";
cout<<"| 1. Program |\n";
cout<<"| 0. Selesai |\n";
cout<<"===================\n\n";
cout<<"Pilih Menu : ";cin>>pilih;
if(pilih==1)
{
system("CLS");
goto pilih;
}
else
exit (0);
pilih:
cout<<"Pilih Jenis Program 1-5:";cin>>x;
cout<<"Masukan Jumlah Baris :";cin>>n;
cout<<endl;
b=1;
c=1;
d=2;
e=4;
f=7;
if(x==1) //program 1
{
for(a=1;b<=n;b++)
{
cout<<" "<<a;
a=a+c;
c=c+d;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
else
if(x==2) //program 2
{
for(a=3;b<=n;b++)
{
cout<<" "<<a;
a=a*2;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
else
if(x==3) //program 3
{
for(a=2;b<=n;b++)
{
cout<<" "<<a;
a=a+e;
e=e+d;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
else
if(x==4) //program 4
{
for(a=1;b<=n;b++)
{
cout<<" "<<a;
a=a+3;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
else
if(x==5) //program 5
{
for(a=9;b<=n;b=b++)
{
cout<<" "<<a;
a=a+f;
f=f+2;
}
cout<<endl;
cout<<"Lagi?[Y/T]";cin>>ask;
if((ask=='y') || (ask=='Y'))
{
system("CLS");
goto atas;
}
}
}
Comments
Post a Comment
Terimakasih telah berkunjung dan berkomentar disini...