Recent Videos

Blogger TemplatesMy Blogger TricksAll Blogger Tricks

Senin, 13 Januari 2014

PROGRAM PERULANGAN




·         PROGRAM MENCARI HURUF VOKAL

#include <iostream>
#include <string.h>
#include <cstdlib>

using namespace std;

int main ()
{
                cout<<"\tPROGRAM MENCARI HURUF VOKAL\n\n";
                cout<<"\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n";
charkalimat[50];
                cout<<"Char = 50\n";
cout<<"*** TuliskanKalimatAnda:\n";
cin.getline (kalimat,50);
inti;
intvokal = 0;
for(i=0; i<strlen(kalimat); i++)
{if (kalimat[i] == 'a' || kalimat[i] == 'A' ||
kalimat[i] == 'i' || kalimat[i] == 'I' ||
kalimat[i] == 'u' || kalimat[i] == 'U' ||
kalimat[i] == 'e' || kalimat[i] == 'E' ||
kalimat[i] == 'o' || kalimat[i] == 'U'  ){
vokal++;                                                                              
}
}
cout<<"\n~~~>jumlahvokal=";
cout<<vokal<<endl;
}
                                                               
//exmpl :
//char kalimat[] = "saya ";
//isikalimat[0] = 's'
//isikalimat[1] = 'a'
//isikalimat[2] = 'y'
//strlenfungsibuatmendapatkanpanjang string, jikaditemukan array berupaa,i,u,e,omakavariabelvokal +1.




·         PROGRAM PERULANGAN SEGITIGA
#include<iostream>
#include <stdlib.h>
using namespace std;
int main()
{
        chartombol;
        intmenu,a,b,c,v,x,y,z;
        menu:
        system ("cls");  
        cout<<"\t\t\t\t KELOMPOK 11\n";
        cout<<"\t\t\t PROGRAM PERULANGAN SEGITIGA\n ";
        cout<<"\t\t===========================================\n ";
        cout<<"\t\t===========================================\n"<<endl;
        cout<<"1.SEGITIGA RATA KIRI\n";
        cout<<"2.SEGITIGA RATA KANAN\n";
        cout<<"3.KOMBINASI SEGITIGA RATA KIRI\n";
        cout<<"4.KOMBINASI SEGITIGA RATA KIRI DAN KANAN\n";
        cout<<"5.SEGITIGA PIRAMID\n";
        cout<<"\nSilahkanMasukkanPerulangan SEGITIGA Yang AndaInginkan (1-5) : ";cin>>menu;
        switch(menu)
       
{
        case 1:
                        system ("cls");
                        cout<<"SEGITIGA RATA KIRI\n\n";
                        cout<<"MasukkanJumlahBaris=";
                        cin>>z;cout<<endl;
                       
                        for(int y=0;y<=z;y++)
                        {
                        for(x=1;x<=y;x++)
                       
                        cout<<"*";
                        cout<<endl;
                        }
                        cout<<"\n";
                        cout<<"\n===========================================\n ";
                        break;
                       
        case 2:
                        system ("cls");
                        cout<<"SEGITIGA RATA KANAN\n\n";
                        cout<<"MasukkanAngka : ";cin>>a;
                        cout<<"\n";
       
                        for(b=0;b<a;b++)
                        {
                        for(c=0;c<a-b;c++)
                        cout<<" ";
                       
                        for(c=0;c<=b;c++)
                        cout<<"*";
                        cout<<"\n";
                        }
                        cout<<"\n";
                        cout<<"\n===========================================\n ";
                        break;
                       
        case 3:
                        system ("cls");
                        cout<<"KOMBINASI SEGITIGA RATA KIRI\n\n";
        cout<<"MasukkanAngka : ";cin>>a;
                        cout<<"\n";
       
                        for(b=0;b<a;b++)
                        {
                        for(c=0;c<a-b;c++)
                        cout<<"*";
                        cout<<"\n";
                        }
                        for(b=0;b<a;b++)
                        {
                        for(c=0;c<=b;c++)
                        cout<<"*";
                        cout<<"\n";
                        }
       
        cout<<"\n";
                        cout<<"\n===========================================\n ";
                        break;
                       
        case 4:
                        system ("cls");
                        cout<<"KOMBINASI SEGITIGA RATA KIRI DAN KANAN\n\n";
                        cout<<"MasukkanJumlahBaris=";
                        cin>>z;cout<<endl;
                        for(int y=1;y<=z;y++)
                        {
                       
                        for(x=1;x<=y;x++)
                       
                        {cout<<"*";}
                       
                        for(v=z; v>=x; v--)
                        {cout<<"  ";}

                        for(v=x;v<x;v++)
       
                        { cout<<"*";}
       
                        for(v=2*(x-1);v>=x; v--)
       
                        { cout<<"*";}
       
                        cout<<"\n";
                        }
                       
                        cout<<"\n";
                        cout<<"\n===========================================\n ";
       
                        break;
                       
        case 5:
                        system ("cls");
                        cout<<"SEGITIGA PIRAMID\n\n";
                        cout<<"MasukkanTinggiPiramid = ";cin>>a;

                        for(x=1; x<=a; x++)
                        {
                                        for(z=a; z>=x; z--)
                                        cout<<" ";

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

                                        cout<<"\n";
                        }
                       
                        cout<<"\n";
                        cout<<"\n===========================================\n ";
       
                        break;
       
                                                                                       
}
                                                        cout<< "Apakahmaumengulangi (Y/T)?";cin>>tombol;
                                                       
                                                        cout<<endl;
                                                        if (tombol == 'Y' || tombol == 'y'){goto menu;}
                                                        else
                                                        {
                                                        cout<< "Selesai";
                                                        }
       
                       
}

OPERASI MATRIKS

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
char tombol;
int menu,ordo,a1,a2,a3,a4,a5,a6,a7,a8,a9,b1,b2,b3,b4,b5,b6,b7,b8,b9;

menu:
system ("color f");
system ("cls");
cout<<"\t\t OPERASI MATRIKS\n";
cout<<"\t\t ===============\n\n";
cout<<"Silahkan Pilih Ordo Matriks \n\n";
cout<<"+------------+\n";
cout<<"| 1.Ordo 2x2 |\n";
cout<<"| 2.Ordo 3x3 |\n";
cout<<"+------------+\n";
cout<<"Pilihan anda= ";cin>>ordo;
cout<<"=====================================\n";
switch(ordo)
{
case 1:
system ("cls");
cout<<"Matriks Ordo 2x2\n\n";
cout << "\tOPERASI 2 MATRIKS ORDO 2x2\n\n";
cout << "Masukkan Matrix A = \n";
cout<<"(1,1)=";cin>>a1;
cout<<"(1,2)=";cin>>a2;
cout<<"(2,1)=";cin>>a3;
cout<<"(2,2)=";cin>>a4;
cout << "\nMatriks A = \n";
cout<<"\t\t"<<a1<<"\t"<<a2<<"\n"<<"\t\t"<<a3<<"\t"<<a4<<"\n\n";
cout << "\nMatriks A^2 = \n";
cout<<"\t\t"<<a1*a1+a2*a3<<"\t"<<a1*a2+a2*a4<<"\n"<<"\t\t"<<a3*a1+a4*a3<<"\t"<<a3*a2+a4*a4<<"\n\n";
cout << "Masukkan Matrix B = \n";
cout<<"(1,1)=";cin>>b1;
cout<<"(1,2)=";cin>>b2;
cout<<"(2,1)=";cin>>b3;
cout<<"(2,2)=";cin>>b4;
cout << "\nMatriks B = \n";
cout<<"\t\t"<<b1<<"\t"<<b2<<"\n"<<"\t\t"<<b3<<"\t"<<b4<<"\n\n";
cout << "\nMatriks B^2 = \n";
cout<<"\t\t"<<b1*b1+b2*b3<<"\t"<<b1*b2+b2*b4<<"\n"<<"\t\t"<<b3*b1+b4*b3<<"\t"<<b3*b2+b4*b4<<"\n\n";
cout<<"matrix (A+B)= \n";
cout<<"\t\t"<<a1+b1<<"\t"<<a2+b2<<"\n"<<"\t\t"<<a3+b3<<"\t"<<a4+b4<<"\n\n";
cout<<"matrix (A-B)= \n";
cout<<"\t\t"<<a1-b1<<"\t"<<a2-b2<<"\n"<<"\t\t"<<a3-b3<<"\t"<<a4-b4<<"\n\n";
cout<<"matrix (B-A)= \n";
cout<<"\t\t"<<b1-a1<<"\t"<<b2-a2<<"\n"<<"\t\t"<<b3-a3<<"\t"<<b4-a4<<"\n\n";
cout<<"matrix (A*B)= \n";
cout<<"\t\t"<<a1*b1+a2*b3<<"\t"<<a1*b2+a2*b4<<"\n"<<"\t\t"<<a3*b1+a4*b3<<"\t"<<a3*b2+a4*b4<<"\n\n";
cout<<"matrix (B*A)= \n";
cout<<"\t\t"<<b1*a1+b2*a3<<"\t"<<b1*a2+b2*a4<<"\n"<<"\t\t"<<b3*a1+b4*a3<<"\t"<<b3*a2+b4*a4<<"\n\n";
cout<<"Det(A)=";
cout<<"\t\t"<<"("<<a1<<"*"<<a4<<")"<<" - "<<"("<<a2<<"*"<<a3<<")"<<"\n"<<"\t\t"<<a1*a4<<" - "<<a2*a3<<" = "<<a1*a4-a2*a3<<"\n\n";
cout<<"Det(B)=";
cout<<"\t\t"<<"("<<b1<<"*"<<b4<<")"<<" - "<<"("<<b2<<"*"<<b3<<")"<<"\n"<<"\t\t"<<b1*b4<<" - "<<b2*b3<<" = "<<b1*b4-b2*b3<<"\n\n";
cout<<"Tr (A)= \n";
cout<<"\t\t"<<"("<<a1<<"+"<<a4<<")"<<" = "<<a1+a4<<"\n\n";
cout<<"Tr (B)= \n";
cout<<"\t\t"<<"("<<b1<<"+"<<b4<<")"<<" = "<<b1+b4<<"\n\n";
break;

case 2:
system ("cls");
cout<<"Matriks Ordo 3x3\n\n";
cout << "\tOPERASI 2 MATRIKS ORDO 3x3\n\n";
cout << "Masukkan Matrix A = \n";
cout<<"(1,1)=";cin>>a1;
cout<<"(1,2)=";cin>>a2;
cout<<"(1,3)=";cin>>a3;
cout<<"(2,1)=";cin>>a4;
cout<<"(2,2)=";cin>>a5;
cout<<"(2,3)=";cin>>a6;
cout<<"(3,1)=";cin>>a7;
cout<<"(3,2)=";cin>>a8;
cout<<"(3,3)=";cin>>a9;
cout << "\nMatriks A = \n";
cout<<"\t\t"<<a1<<"\t"<<a2<<"\t"<<a3<<"\n"<<"\t\t"<<a4<<"\t"<<a5<<"\t"<<a6<<"\n"<<"\t\t"<<a7<<"\t"<<a8<<"\t"<<a9<<"\n\n";
cout << "Masukkan Matrix B = \n";
cout<<"(1,1)=";cin>>b1;
cout<<"(1,2)=";cin>>b2;
cout<<"(1,3)=";cin>>b3;
cout<<"(2,1)=";cin>>b4;
cout<<"(2,2)=";cin>>b5;
cout<<"(2,3)=";cin>>b6;
cout<<"(3,1)=";cin>>b7;
cout<<"(3,2)=";cin>>b8;
cout<<"(3,3)=";cin>>b9;
cout << "\nMatriks B = \n";
cout<<"\t\t"<<b1<<"\t"<<b2<<"\t"<<b3<<"\n"<<"\t\t"<<b4<<"\t"<<b5<<"\t"<<b6<<"\n"<<"\t\t"<<b7<<"\t"<<b8<<"\t"<<b9<<"\n\n";
cout<<"matrix (A+B)= \n";
cout<<"\t\t"<<a1+b1<<"\t"<<a2+b2<<"\t"<<a3+b3<<"\n"<<"\t\t"<<a4+b4<<"\t"<<a5+b5<<"\t"<<a6+b6<<"\n"<<"\t\t"<<a7+b7<<"\t"<<a8+b8<<"\t"<<a9+b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t\t"<<a1*a5*a9+a2*a6*a7+a3*a4*a8<<" - "<<a2*a4*a9+a1*a6*a8+a3*a5*a7<<" = "<<(a1*a5*a9+a2*a6*a7+a3*a4*a8)-(a2*a4*a9+a1*a6*a8+a3*a5*a7)<<"\n\n";
cout<<"Det (B)=";
cout<<"\t"<<b1<<"\t"<<b2<<"\t"<<b3<<"\t"<<"|"<<"\t"<<b1<<"\t"<<b2<<"\n"<<"\t\t"<<b4<<"\t"<<b5<<"\t"<<b6<<"\t"<<"|"<<"\t"<<b4<<"\t"<<b5<<"\n"<<"\t\t"<<b7<<"\t"<<b8<<"\t"<<b9<<"\t"<<"|"<<"\t"<<b7<<"\t"<<a8<<"\n\n";
cout<<"\t"<<"("<<b1<<"*"<<b5<<"*"<<b9<<"+"<<b2<<"*"<<b6<<"*"<<b7<<"+"<<b3<<"*"<<b4<<"*"<<b8<<")"<<"-"<<"("<<b2<<"*"<<b4<<"*"<<b9<<"+"<<b1<<"*"<<b6<<"*"<<b8<<"+"<<b3<<"*"<<b5<<"*"<<b7<<")"<<"\n"<<"\t\t"<<b1*b5*b9+b2*b6*b7+b3*b4*b8<<" - "<<b2*b4*b9+b1*b6*b8+b3*b5*b7<<" = "<<(b1*b5*b9+b2*b6*b7+b3*b4*b8)-(b2*b4*b9+b1*b6*b8+b3*b5*b7)<<"\n\n";
cout<<"Tr (A)=";
cout<<"\t\t"<<"("<<a1<<"+"<<a5<<"+"<<a9<<")"<<" = "<<a1+a5+a9<<"\n\n";
cout<<"Tr (B)=";
cout<<"\t\t"<<"("<<b1<<"+"<<b5<<"+"<<b9<<")"<<" = "<<b1+b5+b9<<"\n\n";
break;
cout <<"\n";
cout<<"\n===========================================\n ";
}
back:

cout << "Apakah mau mengulangi (Y/T)?";cin>>tombol;cout << endl;
if (tombol == 'Y' || tombol == 'y'){goto menu;}
else if (tombol =='T' || tombol == 't') {exit;}
else {goto back;}
}

ini adalah hasil compile:





Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews