C++



PROGRAM LOOPING
C++

1. LOOPING WHILE   
INPUT                                                             
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
void main()
{
                 int i;
                 i=0;
                 while (i<10)
                 {
                 cout<<"stmik bani saleh"<<endl;
                 i++;
                 }
                 cout<<"FINISH";
}
            OUTPUT

2. LOOPING FOR
 INPUT
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
void main()
{
             int banisaleh;
             for (banisaleh=1; banisaleh<1000; banisaleh++)
             cout<<"banisaleh"<<banisaleh<<endl;

}



3. LOOPING FOR
include <iostream.h>
#include <stdio.h>
#include <conio.h>

void main()
{
             int i,t,r;
             cout<<"x  y  z"<<endl;
             for (i=1;i<=2; i++)
             {
             for (t=1;t<=3; t++)
             {
             for (r=1;r<=5; r++)
             {
              cout<<i<<"  "<<t<<"  "<<r<<endl;
              }}}
             }


4.LOOPING FOR
#include <iostream.h>
#include <stdio.h>

void main ()
{
            int suhu [5]={9,8,7,6,5};
            int x;
            for (x=0;x<5;x=x+1)
            {
            cout<<suhu[x] <<endl;
            }

}

5.LOOPING DO WHILE
#include <stdio.h>
#include <conio.h>
main()
{
int bil=2;
clrscr();
do
{
printf(" %d ",bil);
bil+=2;
}
while(bil<=10);
getch();
}


PROGRAM ARRAY
6. ARRAY
#include <iostream.h>
#include <conio.h>
void main ()
{
            int index[3][4]={{5,20,1,11},{4,7,67,-9},{9,0,45,3}};
            int i,j;
            for(i=0;i<=2;i++)
            {
            for(j=0;j<=3;j++)
            {
            cout<<"index ["<<i<<"] ["<<j<<"] ="<<index[i][j]<<endl;
            }
            }
            cout<<endl<<endl;

            for (i=0;i<=2;i++)
            {

            cout<<"{ ";

            for (j=0;j<=3;j++)
            {

            cout<<index[i] [j] <<"   ";
            }
            cout<<"}  "; cout<<endl;
           }
            getch();

OUTPUT




7. ARRAY
#include <iostream.h>
#include <conio.h>
void main ()
{
            int index[3][4];
            int i,j;

            for(i=0;i<=2;i++)
            {
            for(j=0;j<=3;j++)
            {

            cout<<"index ["<<i<<"] ["<<j<<"] =";
            cin>>index [i] [j];
            }

            }

            cout<<endl<<endl;
            for (i=0;i<=2;i++)
            {
            cout<<"{ ";

            for (j=0;j<=3;j++)
            {
            cout<<index[i] [j] <<"   ";
            }
            cout<<"}  ";
            cout<<endl;
            }
            getch();

 }



8. ARRAY
#include <iostream.h>
#include <conio.h>

int main ()
{
            int x,y,z,bil;
            clrscr();
            cout<<"\n @sudiman \n";
            cout<<"\n masukkan nilai segitiga: ";
            cin>>bil;
            cout<<"\n";
            for(x=1;x<=bil;x++)
            {
            for(z=bil;z>=x;z--)
            cout<<"   ";
            for (z=x;z<2*x;z++)
            {
            y=z%10;
            cout<<"  Y  ";
            }
            for (z=2*(x-1);z>=x;z--)
            {
            y=z%10;
            cout<<"   ";
            }
            cout<<"\n";
            }
            getch();
            return 0;

}





9. ARRAY
#include <iostream.h>
#include <conio.h>
int main ()
{
            int x,z;
            clrscr();

            for(x=1;x<=5;x++)
            {
            for(z=1;z<=x;z++)
            {
            cout<<"*";
             }
             cout<<endl;
             }
             getch();
}

10. ARRAY
#include <iostream.h>
#include <conio.h>
int main ()
{
            int x,z;
            clrscr();

            for(x=1;x<=5;x++)
            {
            for(z=x;z<=5;z++)
            {
            cout<<"*";
             }
             cout<<endl;
             }
             getch();
}

11. ARRAY
#include <iostream.h>
int main()
{
             int data[5];
             int x,y;
             int   nilai_terkecil=999, nilai_terbesar=0;
             float rata_rata, total=0;
             cout <<"Tampilkan 5 Buah Data"<<endl;
             cout <<"====================="<<endl;
             for (x=0;x<5;x++)
             {
                          cout <<"Data Ke-"<<x+1<<"   =";
                          cin >> data[x];
                          total=total+data[x];
                          rata_rata=total/5;


                                                if (data[x] > nilai_terbesar)
                                                {
                                                             nilai_terbesar=data[x];
                                                }
                                                if (data[x] < nilai_terkecil)
                                                {
                                                             nilai_terkecil=data[x];
                                                }
             }
             cout <<"====================="<<endl;
             cout <<"Total           = "<<total<<endl;
             cout <<"Rata Rata       = "<<rata_rata<<endl;
             cout <<"Nilai Terbesar  = "<<nilai_terbesar<<endl;
             cout <<"Nilai Terkecil  = "<<nilai_terkecil<<endl;
             cout <<"=====================";
             return 0;
}

Dan Tugasyang lainnya ada di sini