Minggu, 11 Maret 2012

2 matrik berordo m*n


#include<iostream.h>

void main()
{
 int i,j,k,kolm,barm,barn,koln;
 int data1[25][25],data2[25][25],hasil[25][25];

 do
 {
 cout<<"Program Perkalian Matrix"<<endl;
 cout<<endl;
 cout<<"Input Matrix M: "<<endl;
 cout<<"Jml kolom M: "; cin>>kolm;
 cout<<"Jml baris M: "; cin>>barm;
 cout<<"Input Matrix N: "<<endl;
 cout<<"Jml kolom N: "; cin>>koln;
 cout<<"Jml baris N: "; cin>>barn;
 }
 while (kolm!=barn);

 cout<<endl;

 for (i=1; i<=barm; i++)
 {
for (j=1; j<=kolm; j++)
{
cout<<"Data M ["<<i<<","<<j<<"]: "; cin>>data1[i][j];
}
 }

 cout<<endl;

 for (i=1; i<=barn; i++)
 {
for (j=1; j<=koln; j++)
{
cout<<"Data N ["<<i<<","<<j<<"]: "; cin>>data2[i][j];
}
 }

 for (i=1; i<=barm; i++)
 {
for (j=1; j<=koln; j++)
{
for (k=1; k<=kolm; k++)
{
hasil[i][j]=hasil[i][j] + data1[i][k] * data2[k][j];
}
}
 }

cout<<endl;
cout<<"Hasil Perkalian Matrix M x N: "<<endl;

 for (i=1; i<=barm; i++)
 {
for (j=1; j<=koln; j++)
{
cout<<hasil[i][j]<<" ";
}
cout<<endl;
 }

 }

menghitung elemen array 1,3,5,4,7,2,99,16,45,67,89,45


#include <iostream.h>
void main()
{
int x[12]={1,3,5,4,7,2,99,16,45,67,89,45};
int i,jum;
jum=0;
for(i=0;i<12;i++)
{
cout<<x[i];
jum++;
}
cout<<" \n"<<endl;
cout<<"Jumlah Elememen : "<<jum;
}

Rabu, 07 Maret 2012

PROGRAM BILANGAN PANGKAT C++


#include<iostream.h>
#include<conio.h>
void Header()
{
cout<<"program pangkat 3"<<endl<<endl;
}

int Jumlah(int Bil)
{
int Total;
Total=Bil*Bil*Bil;
return(Total);
}
void main()
{
 clrscr();
int X,Total=100000;
 Header();
 cout<<"Masukkan angka=";
 cin>>X;
 Total=X*X*X;
 cout<<"Hasil="<<Total<<endl;
 getch();
 }

program luas suatu bangun C++


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

void input(int*pj,int*lb)
{
cout<<"inputkan panjang:";cin>>*pj;
cout<<"inputkan lebar:";cin>>*lb;
}
void hitung(int panjang,int lebar,int&luas)
{
luas=(panjang*lebar);
}
void cetak(int luas)
{
cout<<"luas persegi"<<luas<<endl;
}

void main()
{
int panjang,lebar,luas;
input(&panjang,&lebar);
hitung(panjang,lebar,luas);
cetak(luas);
getch();
}

Program C++ menampilkan 5 buah bilangan


#include <iostream.h>
#include <conio.h>
void main()
{
int r,x,z;
x=8;
for(r=5;r>=1;r--)
{
z=x-r
cout<<x<<"-"<<"n"<<z;(cout<<x<<"-"<<r<<"="<<z;)
cout<<endl;
}
getch();
}

penggunaan while atau for pada C++


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

int main()
{
int A=4;
int B;
do
{
B=1;
do
{
cout<<'*';
B++;
}while(A>=B);
cout<<'\n';
A--;
}while(A>=1);

return 0;
}

program C++ mencetak deret 10-1


#include<iostream.h>
void main()
{
int i;
for(i=10;i>0;i--)
 cout<<i<<endl;
}

program c++ status bilangan ganjil genap

#iclude <iostream.h>
 void main()
{
int angka;
cout<<"Masukkan nilai bilangan:";
cin>>angka;
if(angka%2==0)
cout<<"Bilangan"angka<<"adalah bilangan genap";
else
cout<<"Bilangan"angka<<"adalah bilangan ganjil";
}

program C++ menentukan nilai mahasiswa


#include <iostream.h>
void main()
{
int nilai;
cout<<"nilai mahasiswa"<<endl<<endl;
cout<<"masukkan nilai anda:";
cin>>nilai;
cout<<endl;
if((100.00>=nilai)&&(nilai>=8.00))
cout<<"A";
else
if((7.99>=nilai)&&(nilai>=7.00))
cout<<"B";
if((6.99>=nilai)&&(nilai>=6.00))
cout<<"C";
if((5.99>=nilai)&&(nilai>=5.00))
cout<<"D";
if((4.99>=nilai)&&(nilai>=4.00))
cout<<"E";
if((3.99>=nilai)&&(nilai>=0.00))
cout<<"E";
}

program C++ menampilkan identitas menggunakan proses I/O C++


#include<stdio.h>
#include<iostream.h>
void main ()
{
char        NIM[20],
NAMA[25],
FAKULTAS[20],
JURUSAN[20];
printf("\t      :Ahmad Khamdi Musthofa\n");
printf("\t   LABORATORIUM SIMULASI\n");
printf("\tINSTITUT ADHI TAMA SURABAYA\n");
printf("========================================\n");

cout<<"NIM       :";
cin>>NIM;

printf("NAMA      :");
scanf("%s",&NAMA);

cout<<"FAKULTAS  :";
cin>>FAKULTAS;

cout<<"JURUSAN   :";
cin>>JURUSAN;

printf("========================\n");
printf("IDENTITAS ANDA   :\n");
cout<<"NIM   :";
cout<<NIM<<  '\n';
cout<<"NAMA  :";
cout<<NAMA<<'\n';
printf("=======================\n");
}

program menampilkan identitas C++


prt sc

tugas pendahuluan
Ahmad khamdi musthofa
klompok A2

#include <iostream.h>
#include <string.h>
int main()
{
char info [100];
strcpy( info," >> labolatorium simulasi <<");
cout << info ;
cout <<"\n";
strcpy( info,"________________________________________");
cout << info ;
cout <<"\n" ;
strcpy( info," NPM           :03.2011.1.06825");
cout << info ;
cout <<"\n" ;
strcpy( info," Nama          :Ahmad Khamdi Musthofa");
cout << info ;
cout <<"\n" ;
strcpy( info," Fakultas      :Teknologi Industri");
cout << info ;
cout <<"\n" ;
strcpy( info," Jurusan       :Teknik Elektro");
cout << info;
cout <<"\n";
strcpy( info,"________________________________________");
cout << info ;

return 0;
}