Kamis, 19 April 2018


Perulangan for-if
 
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int main(){

      int num;
      cout<<”masukkan angka yang diinginkan”;
      cin>>num;

      for(int i=1; i<=num; i++){
             for(int j=1; j<=num-1; j++){
                   cout<<” “;
             }
             for(int k=1; k<=i; k++){
                  if(i<=10) cout<<”    “<<i;
             }
             cout<<endl;
         }
getch();
}



 


Perulangan for-else if
 

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int main(){

      int num;
      cout<<”masukkan angka yang diinginkan”;
      cin>>num;

      for(int i=1; i<=num; i++){
             for(int j=1; j<=num-1; j++){
                   cout<<” “;
             }
             for(int k=1; k<=i; k++){
                  if(i<=10) cout<<”    “<<i;
                  else cout<<”     “<<i;
             }
             cout<<endl;
         }
getch();
}

 









Perulangan while-if
 

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

Int main()
{
int b,a=1;
while(a<=11){
 b=1; while(b<=a){
cout<<setw(3)<<a; b++;
}
cout<<”\n”; a++;
}
if(a<=10) cout<<” “<<a;
cout<<endl;
getch();
}

 
 





Perulangan while-else if
 

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

Int main()
{
int b,a=1;
while(a<=11){
 b=1; while(b<=a){
cout<<setw(3)<<a; b++;
}
cout<<”\n”; a++;
}
if(a<=10) cout<<” “<<a;
else cout<<” 11 11 11 11 11 11 11 11 11 11 “<<a;
cout<<endl;
getch();
}

  





Perulangan do while-if

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

int main(){

int a=1,b;
do
{
 b=1;
do
{
cout<<setw(3)<<a; b++;
}
while(b<=a);
cout<<”\n”; a++;
}
while(a<=10);
{
if(a<=10) cout<<” “<<a;
}
cout<<endl;
getch();
}

  




Perulangan do while-else if
 

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

void main()
{
int a=1,b;
do
{
 b=1;
do
{
cout<<setw(3)<<a; b++;
}
while(b<=a);
cout<<”\n”; a++;
}
while(a<=10);
cout<<” “;

if(a<=10) cout<<”    “<<a;
else cout<<”11 11 11 11 11 11 11 11 11 11 “<<a;
cout<<endl;
getch();
}

 

Tidak ada komentar:

Posting Komentar