//Prefix, Postfix, Increment, Decrement dan Pemanggilan Function dg Parameter
#include <iostream>
using namespace std;
int pilihan,bil,bil_baru;
void postfixIncrement(int bil)
{
bil_baru=bil++;
cout<<"Nilai bil baru : "<<bil_baru<<endl;
cout<<"Nilai bil : "<<bil<<endl;
}
void prefixIncrement(int bil)
{
bil_baru=++bil;
cout<<"Nilai bil baru : "<<bil_baru<<endl;
cout<<"Nilai bil : "<<bil<<endl;
}
void prefixDecrement(int bil)
{
bil_baru=--bil;
cout<<"Nilai bil baru : "<<bil_baru<<endl;
cout<<"Nilai bil : "<<bil<<endl;
}
void postfixDecrement(int bil)
{
bil_baru=bil--;
cout<<"Nilai bil baru : "<<bil_baru<<endl;
cout<<"Nilai bil : "<<bil<<endl;
}
int main()
{
cout<<"Silahkan pilih operasi : \n";
cout<<"1. Prefix Increment\n";
cout<<"2. Postfix Increment\n";
cout<<"3. Prefix Decrement\n";
cout<<"4. Postfix Decrement\n";
cout<<"Pilihan Anda : ";
cin>>pilihan;
cout<<"Masukan bilangan : ";
cin>>bil;
if(pilihan==1)
{
prefixIncrement(bil);
}
else if(pilihan==2)
{
postfixIncrement(bil);
}
else if(pilihan==3)
{
prefixDecrement(bil);
}
else if(pilihan==4)
{
postfixDecrement(bil);
}
else
cout<<"Pilihan hanya 1-4.";
return 0;
}
//Loop Inside Loop
#include <iostream>
using namespace std;
int main()
{
for(int i=0;i<5;i++)
{
for(int j=1;j<6;j++)
{
cout<<i<<j<<"-";
if(i==0 and j==5)
{
cout<<endl;
}
else if(i==1 and j==5)
{
cout<<endl;
}
else if(i==2 and j==5)
{
cout<<endl;
}
else if(i==3 and j==5)
{
cout<<endl;
}
}
}
return 0;
}
No comments:
Post a Comment