Transpose Matriks
#include<stdio.h>
int main()
{
int i, j;
int matrix[3][3], transpose[3][3];
printf("Masukkan elemen matrix A[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("M[%d,%d] = ", i+1, j+1);
scanf("%d", &matrix[i][j]);
}
}
/* TRANSPOSE –> baris jadi kolom dan sebaliknya */
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
transpose[j][i] = matrix[i][j];
}
}
/* TAMPILKAN MATRIK A */
printf("\nMatrik A[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%5d", matrix[i][j]);
}
printf("\n");
}
/* TAMPILKAN TRANSPOSE MATRIK A */
printf("Transpose Matrik A[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%5d", transpose[i][j]);
}
printf("\n");
}
}
Menghitung Deret angka
#include <iostream>
#include <cstdlib>
using namespace std;
int main (){
//deklarasi
int aw,ak,baw,bak,i;
float j;
//input dari user
cout<<endl<<endl<<endl;
cout<<" >>Program menghitung deret angka"<<endl;
cout<<" >>Ibrahim Siregar"<<endl<<endl;
cout<<" Masukkan bilangan awal : ";
cin>>baw;
cout<<" Masukkan maksimal bilangan : ";
cin>>bak;
cout<<" Masukkan nilai pembagi pertama : ";
cin>>aw;
cout<<" Masukkan nilai pembagi ke dua : ";
cin>>ak;
cout<<endl;
j=0;
cout<<" >> Deret angka : ";
//proses
for (i=baw; i<=bak; i++){
if (i%aw == 0 & i%ak == 0){
cout<<i<<" ";
j=j+i;
}
}
cout<<endl<<endl;
cout<<" Jumlah bilangan deret : "<<j<<endl<<endl;
system ("pause");
}
Penjumlahan Matriks 3x3
#include<stdio.h>
int main()
{
int i, j, x;
int matrixa[3][3], matrixb[3][3], matrixc[3][3];
printf("Masukkan elemen Matrix-A[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("A[%d,%d] = ", i+1, j+1);
scanf("%d", &matrixa[i][j]);
}
}
printf("Masukkan elemen Matrix-B[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("B[%d,%d] = ", i+1, j+1);
scanf("%d", &matrixb[i][j]);
}
}
/* PENJUMLAHAN ( matrixa + matrixb = matrixc ) */
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
matrixc[i][j] = matrixa[i][j] + matrixb[i][j];
}
}
/* Tampilkan Matrix A */
printf("\nMatrix A[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%5d", matrixa[i][j]);
}
printf("\n");
}
/* Tampilkan Matrix B */
printf("\nMatrix B[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%5d", matrixb[i][j]);
}
printf("\n");
}
/* Tampilkan Matrix C */
printf("\nMatrix C[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%5d", matrixc[i][j]);
}
printf("\n");
}
}
int matrix[3][3];
int main()
{
// asigning values, I suppose this is done allready.
for(int x=0;x<3;x++)
{
for(int y=0;y<3;y++)
{
matrix[x][y]=1;
}
}
// showing the matrix on the screen
for(int x=0;x<3;x++) // loop 3 times for three lines
{
for(int y=0;y<3;y++) // loop for the three elements on the line
{
cout<<matrix[x][y]; // display the current element out of the array
}
cout<<endl; // when the inner loop is done, go to a new line
}
return 0; // return 0 to the OS.
}
Determinan Matriks
#include <iostream.h>
int main()
{
float A[3][3];// the matrix that is entered by user
float B[3][3];//the transpose of a matrix A
float C[3][3];//the adjunct matrix of transpose of a matrix A not adjunct of A
double X[3][3];//the inverse
int i,j;
float x,n=0;//n is the determinant of A
cout<<"========== Enter matrix A ===============\n";
for(i=0;i<3;i++)
{ cout<<endl;
for(j=0;j<3;j++)
{
cout<<" A["<<i<<"]["<<j<<"]= ";
cin>>A[i][j];
B[i][j]=0;
C[i][j]=0;
}
}
for(i=0,j=0;j<3;j++)
{
if(j==2)
n+=A[i][j]*A[i+1][0]*A[i+2][1];
else if(j==1)
n+=A[i][j]*A[i+1][j+1]*A[i+2][0];
else
n+=A[i][j]*A[i+1][j+1]*A[i+2][j+2];
}
for(i=2,j=0;j<3;j++)
{
if(j==2)
n-=A[i][j]*A[i-1][0]*A[i-2][1];
else if(j==1)
n-=A[i][j]*A[i-1][j+1]*A[i-2][0];
else
n-=A[i][j]*A[i-1][j+1]*A[i-2][j+2];
}
cout<<"\n========== The matrix A is================\n";
for(i=0;i<3;i++)
{
cout<<endl;
for(j=0;j<3;j++)
{
cout<<" A["<<i<<"]["<<j<<"]= "<<A[i][j];
}
}
cout<<endl<<endl;
cout<<"===========================================\n"<<endl;
cout<<"The determinant of matrix A is "<<n<<endl<<endl;
cout<<"============================================"<<endl;
if(n!=0) x=1.0/n;
else
{
cout<<"Division by 0, not good!\n";
cout<<"======================================\n"<<endl;
return 0;
}
cout<<"\n==== The transpose of a matrix A====\n";
for(i=0;i<3;i++)
{
cout<<endl;
for(j=0;j<3;j++)
{
B[i][j]=A[j][i];
cout<<" B["<<i<<"]["<<j<<"]= "<<B[i][j];
}
}
cout<<endl<<endl;
C[0][0]=B[1][1]*B[2][2]-(B[2][1]*B[1][2]);
C[0][1]=(-1)*(B[1][0]*B[2][2]-(B[2][0]*B[1][2]));
C[0][2]=B[1][0]*B[2][1]-(B[2][0]*B[1][1]);
C[1][0]=(-1)*(B[0][1]*B[2][2]-B[2][1]*B[0][2]);
C[1][1]=B[0][0]*B[2][2]-B[2][0]*B[0][2];
C[1][2]=(-1)*(B[0][0]*B[2][1]-B[2][0]*B[0][1]);
C[2][0]=B[0][1]*B[1][2]-B[1][1]*B[0][2];
C[2][1]=(-1)*(B[0][0]*B[1][2]-B[1][0]*B[0][2]);
C[2][2]=B[0][0]*B[1][1]-B[1][0]*B[0][1];
cout<<"\nThe adjunct matrix of transpose of the matrix A\n";
for(i=0;i<3;i++)
{
cout<<endl;
for(j=0;j<3;j++)
{
cout<<" C["<<i<<"]["<<j<<"]= "<<C[i][j];
}
}
cout<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
X[i][j]=C[i][j]*x;
}
}
cout<<"\nInvers Matriks Adalah\n";
for(i=0;i<3;i++)
{ cout<<endl;
for(j=0;j<3;j++)
{
cout<<" X["<<i<<"]["<<j<<"]= "<<X[i][j];
}
}
cout<<endl<<endl;
return 0;
}
Menghitung Deret angka
#include <iostream>
#include <cstdlib>
using namespace std;
int main (){
//deklarasi
int aw,ak,baw,bak,i;
float j;
//input dari user
cout<<endl<<endl<<endl;
cout<<" >>Program menghitung deret angka"<<endl;
cout<<" >>Ibrahim Siregar"<<endl<<endl;
cout<<" Masukkan bilangan awal : ";
cin>>baw;
cout<<" Masukkan maksimal bilangan : ";
cin>>bak;
cout<<" Masukkan nilai pembagi pertama : ";
cin>>aw;
cout<<" Masukkan nilai pembagi ke dua : ";
cin>>ak;
cout<<endl;
j=0;
cout<<" >> Deret angka : ";
//proses
for (i=baw; i<=bak; i++){
if (i%aw == 0 & i%ak == 0){
cout<<i<<" ";
j=j+i;
}
}
cout<<endl<<endl;
cout<<" Jumlah bilangan deret : "<<j<<endl<<endl;
system ("pause");
}
Penjumlahan Matriks 3x3
#include<stdio.h>
int main()
{
int i, j, x;
int matrixa[3][3], matrixb[3][3], matrixc[3][3];
printf("Masukkan elemen Matrix-A[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("A[%d,%d] = ", i+1, j+1);
scanf("%d", &matrixa[i][j]);
}
}
printf("Masukkan elemen Matrix-B[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("B[%d,%d] = ", i+1, j+1);
scanf("%d", &matrixb[i][j]);
}
}
/* PENJUMLAHAN ( matrixa + matrixb = matrixc ) */
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
matrixc[i][j] = matrixa[i][j] + matrixb[i][j];
}
}
/* Tampilkan Matrix A */
printf("\nMatrix A[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%5d", matrixa[i][j]);
}
printf("\n");
}
/* Tampilkan Matrix B */
printf("\nMatrix B[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%5d", matrixb[i][j]);
}
printf("\n");
}
/* Tampilkan Matrix C */
printf("\nMatrix C[3x3]\n");
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%5d", matrixc[i][j]);
}
printf("\n");
}
}