1. Program Perhitungan Perkalian Matriks
This program :
#include<stdio.h>
#include<conio.h>
#include "E:\TUGAS KULIAH\SEMESTER 1\PEMROGRAMAN DAN ALGORITMA\KUMPULAN PEMROGRAMAN DAN ALGORITMA\gotoxy.h"
main()
{
int i,j,k,N,M,P,A[8][8],B[8][8],C[8][8],br,kl;
gotoxy(45,2);printf("PERKALIAN MATRIKS");
gotoxy(3,4);printf("\n\n\n Entry Ordo");
gotoxy(3,6);printf("\n\n\tJumlah Baris Matriks 1 (M):");
scanf("%d",&M);
gotoxy(3,8);printf("\n\n\tJumlah Kolom Matriks 1 (N):");
scanf("%d",&N);
printf("\t(=Jumlah Baris)");
gotoxy(3,11);;printf("\n\n\tJumlah Kolom Matriks 2 (P):");
scanf("%d",&P);
gotoxy(3,12);printf("\n\n\n Entry Elemen-Elemen Matriks 1:\n\n");
br=17;
kl=5;
for(i=1;i<=M;i++)
{
for(j=1;j<=N;j++)
{
gotoxy(kl,br);printf("...");
kl=kl+6;
}
br++;
kl=5;
}
br=17;
kl=5;
for(i=1;i<=M;i++)
{
for(j=1;j<=N;j++)
{
gotoxy(kl,br);scanf("%d",&A[i][j]);
gotoxy(kl,br);printf("%3d",A[i][j]);
kl=kl+6;
}
br++;
kl=5;
}
gotoxy(3,20);printf("\n\n\n Entry Elemen-Elemen Matriks 2:\n\n");
br=25;
kl=5;
for(i=1;i<=N;i++)
{
for(j=1;j<=P;j++)
{
gotoxy(kl,br);printf("...");
kl=kl+6;
}
br++;
kl=5;
}
br=25;
kl=5;
for(i=1;i<=N;i++)
{
for(j=1;j<=P;j++)
{
gotoxy(kl,br);scanf("%d",&B[i][j]);
gotoxy(kl,br);printf("%3d",B[i][j]);
kl=kl+6;
}
br++;
kl=5;
}
for(i=1;i<=M;i++)
for(j=1;j<=P;j++)
{
C[i][j]=0;
for(k=1;k<=N;k++)
C[i][j]=C[i][j]+A[i][k]*B[k][j];
}
printf("\n\nSehingga:");
printf("\n\t C=A*B\n");
br=32;
kl=5;
for(i=1;i<=M;i++)
{
for(j=1;j<=P;j++)
{
gotoxy(kl,br);printf("%3d",C[i][j]);
kl=kl+6;
}
br++;
kl=5;
}
getch();
}
jangan lupa menyisipkan file hider gotoxy dan pastikan alamat nya sudah benar.
Kalau kalian ingin file jadi nya tinggal download di sini
2. Program untuk menentukan akar-akar persamaan
#include <stdio.h>
#include <conio.h>
#include <math.h>
main ( )
{ float X1, X2, det, a, b, c, im;
printf ("\n\n\n\t\t PROGRAM AKAR PERSAMAAN KUADRAT ");
printf ("\n\t\t ============================== ");
printf ("\n\t\t Oleh : Mohammad Agung Dirmawan \n");
printf ("\n\n\t* Persamaan Kuadrat: Y = aX^2 + bX +c ");
printf ("\n\n\t* Masukkan Koefisien Persamaan: \n");
printf ("\n\t\tKoefisien pertama(a) = ");scanf("%f",&a);
printf ("\t\tKoefisien kedua(b) = ");scanf("%f",&b);
printf ("\t\tKoefisien ketiga(c) = ");scanf("%f",&c);
det= b*b - 4*a*c ;
printf("\n\n\t* Determinan = %.3f ", det);
printf("\n\n\t* Nilai-Nilai Akar Persamaan tsb :");
if(det>=0)
if(det==0)
{
X1=-b /(2*a); X2=X1;
printf("\n\t (REAL KEMBAR)\n");
printf("\n\t\tX1 = %.3f",X1);
printf("\n\t\tX2 = %.3f",X2);
}
else
{ X1=(-b+sqrt(det))/(2*a);
X2=(-b-sqrt(det))/(2*a);
printf("\n\t (REAL BERBEDA)\n");
printf("\n\t\tX1 = %.3f",X1);
printf("\n\t\tX2 = %.3f",X2);
}
else
{
X1=-b/(2*a); X2=X1;
im= (sqrt(-det))/(2*a);
printf("\n\t (IMAJINER BERBEDA)\n");
printf("\n\t\tX1 = %.3f + %.3f i",X1,im );
printf("\n\t\tX2 = %.3f - %.3f i",X2,im );
}
printf("\n\n");
}
kalian bisa langsung kopas ke kode blok nya . . .
Tidak ada komentar:
Posting Komentar