Program Newton Raphson (MetNum)

Berikut adalah contoh program Newton Rhapson Metode Numerik dengan menggunakan bahasa pemrograman pascal :

uses crt;

label ulang;

var x,x1,y,y1,z,f,f1,f2 : real ;

i : integer ;

ab : char ;

begin

ulang :

clrscr;

repeat

begin

writeln (‘Tentukan akar dari persamaan f(x)=3x+sin(x)+exp dengan metode newton rapahson’); write (‘masukkan nilai x1 =’);

readln (x1);

y1 := 3 * x1 + sin(x1) – exp(x1);

f1 := 3 + cos(x1) – exp(x1);

f2 := – sin(x1) – exp(x1);

z := (y1*f2) / exp (f1*f1);

writeln (‘nilai f(x1) = ‘,y1:0:5);

writeln (‘nilai f(x1) = ‘,f1:0:5);

writeln (‘nilia f(x1) = ‘,f2:0:5);

if abs (z) < 1 then writeln (‘nilai x1 ok memenuhi syarat yaitu (‘,z:0:5,’)(1′);

end;

until abs (z) < 1;

readln;

i := 1;

writeln (‘penyelesaian persamaan karakteristik dengan metode newton raphson’);

writeln (‘—————————————————————–‘);

writeln (‘n n f(x) error ‘);

writeln (‘—————————————————————–‘);

repeat

begin

i := i + 3;

x := x1 – (y1/f1); y := 3 * x + sin (x) – exp (x);

f := 3 + cos (x) – exp (x);

if i < 10 then

writeln (‘:’,i,’::’,x,’::’,y,’::’,abs (y),’:’)

else

writeln (‘:’,i,’::’,x,’::’,y,’::’,abs (y),’:’); x1 := x ; y1 := y ;

f1 := f ;

end;

until abs (y) < 1E-08;

writeln (‘—————————————————————–‘);

writeln (‘akar persamaannya x=’,x);

writeln (‘errornya = ‘,abs (y));

writeln (‘apakah anda ingin mengulanginya (y/t):’);

readln (ab);

if (ab = ‘y’) or (ab = ‘Y’) then

begin

goto ulang;

end;

end.

^Rachmatika Irfani^

Program Regulafalsi (MetNum)

Berikut adala contoh program Regulafalsi Metode Numerik dengan menggunakan bahasa pemrograman pascal :

uses crt;
label ulang ;
var
x1, x2, x3, y1, y2, y3 : real ;
i : integer ;
ab : char ;
data1 : real ;
begin
ulang :
clrscr ;
writeln ( ‘ tentukan nilai akar dari persamaan f(x)= x3 x^3 + x^2 – 3x – 3 – 0 dengan metode regula falsi ‘) ;
write ( ‘ masukan nilai x1 = ‘ ) ; readln (x1);
y1 := x1 * x1 * x1 + x1 * x1 – 3 * x1 – 3 ;
writeln ( ‘ nilai f(x) = ‘, y1 : 0 : 4);
repeat
begin
write ( ‘ masukan nilai x2 = ‘ ) ; readln (x2);
y2 := x2 * x2 * x2 + x2 * x2 – 3 * x2 – 3;
write ( ‘ nilai f(x2) = ‘ , y2 : 0 : 4 ) ;
end ;
if ( y1 * y2 ) < 0 then
writeln ( ‘ syarat nilai OK ‘ )
else
writeln ( ‘ nilai x2 tidak sesuai ‘ );
until ( y1 * y2 ) < 0 ;
writeln ;
writeln ( ‘ penyelesaian karakteristik dengan metode regulafalsi : ‘ ) ;
writeln ( ‘ ======================================================== ‘ ) ;
writeln ( ‘ N x f(x) error ‘ ) ;
writeln ( ‘ ======================================================== ‘ ) ;
repeat
begin
i := i + 1 ; x3 := (x2 – (y2/( y2 – y1 )) * ( x2 – x1 ));
y3 := x3 * x3 * x3 + x3 * x3 – 3 * x3 – 3;
if i < 10 then
writeln (”,i,”,x3,’:’,y3,’:’,abs (y3),’:’);
if y1 * y3 < 0 then
begin
x2 := x3 ; y2 := y3;
end
else
begin
x1 := x3 ; y1 := y3;
end;
end;
until abs (y3) <1e-08;
writeln ( ‘ ——————————————————– ‘ );
writeln ( ‘ akar persamaannya = , ‘ , x3 ) ;
writeln ( ‘ errornya = , ‘ , abs(y3)) ;
writeln ( ‘ ——————————————————– ‘ );
writeln ( ‘ apakah anda ingin mengulanginya (y/t)’ ) ;
readln (ab) ;
if ( ab = ‘y’ ) or ( ab = ‘Y’ ) then
begin
goto ulang
end ;
end.

^Rachmatika Irfani^

Program Biseksi (MetNum)

Berikut adalah contoh program Biseksi Metode Numerik dengan menggunakan bahasa pemrograman pascal :

program biseksi;
uses crt;
label ulang;
var
x1, x2, x3, y1, y2, y3 : real;
i : integer;
ab : char;
begin
ulang:
clrscr;
writeln (‘Tentukan nilai akar dari persamaan f(x)=x^3+x^2-3x-3=0 dengn Metode biseksi’);
write (‘Masukan nilai x1= ‘);
readln (x1);
y1 := x1*x1*x1+x1*x1-3*x1-3;
writeln (‘Nilai f(x1)= ‘, y1:0:4);
repeat
begin
write (‘masukan nilai x2 = ‘);
readln (x2);
y2 := x2*x2*x2+x2*x2-3*x2-3;
write (‘Nilai f(x2) = ‘, y2:0:4);
end;
if (y1*y2) < 0 then
writeln (‘Syarat Nilai ok’)
else
writeln(‘Nilai x2 Belum Sesuai’);
until (y1*y2) <0;
i := 2;
writeln;
writeln(‘ Penyelesaian Persamaan dengan metode Biseksi, Nilai x1= ‘, x1:0:2,’ & x2= ‘,x2:0:2);
writeln(‘—————————————————————————‘);
writeln(‘ n               x               f(x)                    error             ‘);
writeln(‘—————————————————————————‘);
repeat
begin
i := i+1; x3 := (x1 + x2) /2;
y3 := x3*x3*x3+x3*x3-3*x3-3;
if (i mod 10)=0 then readln;
if i<10 then
writeln(‘ ‘,i,’ :: ‘,x3,’ ::’,y3,’ :: ‘,abs( y3 ),’ ::’)
else writeln(i,’ :: ‘,x3,’ :: ‘,y3,’ :: ‘,abs( y3 ),’ ::’);
if ( y1*y3 ) <0 then
begin
x2 := x3;
end else
begin
x1 := x3;
end;
end;
until abs( y3)<1E-07;
writeln(‘——————————————————————–‘);
writeln(‘akar persamaannya = ‘,x3);
writeln(‘errornya = ‘,abs( y3 ));
writeln(‘——————————————————————–‘);
write(‘Apakah anda ingin mengulanginya (y/t): ‘);
readln(ab);
if (ab=’y’) or (ab=’Y’) then
begin
goto ulang;
end
else
end.

^Rachmatika Irfani^

Program Tabulasi (MetNum)

Berikut adalah contoh program Tabulasi Metode Numerik dengan menggunakan bahasa pemrograman pascal :

program metode_tabulasi;
uses crt;
label ulang;
var x,x1,x2,xa,xb,xc,y,y1,y2,ya,yb:real;
    i,j,k:integer;
    ab:char;
begin
     ulang:
     clrscr;
     writeln(‘Tentukan akar penyelesaian dengan metode tabulasi dari f(x)=x^3-7x+1’);
     writeln;
     write(‘Masukkan nial x1 = ‘);
     readln(x1);
     y1 := x1 * x1 * x1 -7 * x1 + 1;
     writeln (‘ f(‘,x1:0:2,’) = ‘,y1:0:4);
     repeat
     begin
          write(‘Masukan nilai x2 = ‘);
          readln(x2);
          y2:= x2 * x2* x2 -7 * x2 + 1;
          writeln(‘ f (‘,x2:0:2,’) = ‘,y2:0:4);
          writeln;
          writeln(‘Syarat (x1 * x2) < 0 ‘);
          write(‘x1 * x2 = ‘, y1 * y2 :0:5);
          if (y1 * y2) < 0 then write(‘Nilai OK’)
          else write(‘Nilai tidak sesuai’);
          readln;
     end;
     until (y1 * y2) < 0 ;
     clrscr;
     k := 0;
     repeat
     begin
          k := k + 1;
          if x1 > x2 then
          begin
                xa := x2;
                xb := x1;
          end
          else
          begin
                xa := x2;
                xb := x1;
          end;
          xc:= (xa – xb) / 10;
          i := 0;
          repeat
          begin
               i := i + 1;
               x := xb + xc * i;
               ya := x * x * x – 7 * x + 1;
               yb := (x – xc) * (x – xc) * (x – xc) – 7 * (x – xc) + 1;
          end;
          until (ya * yb) < 0;
          x1 := x;
          x2 := x – xc;
          writeln(‘Tabulasi ke-‘,k);
          writeln(‘————————————————————‘);
          writeln(‘n              x              f(x)              error       ‘);
          writeln(‘————————————————————‘);
          for j := 1 to 9 do
          begin
               x := xb + xc * (j – 1);
               y := x * x * x – 7 * x + 1;
               writeln(”,j,’ ::’,x,’ ::’,y,’ ::’,abs(y),’ ::’);
          end;
          for j := 10 to 11 do
          begin
               x := xb + xc * (j – 1);
               y := x * x * x – 7 * x + 1;
               writeln(”,j,’ ::’,x,’ ::’,y,’ ::’,abs(y),’ ::’);
          end;
          writeln(‘————————————————————‘);
     end;
     readln;
     until abs(y) < 10e – 8;
     writeln(‘Akar pendekatannya adalah x = ‘,x);
     writeln(‘error = ‘,abs(y));
     writeln;
     write(‘Apakah anda ingin mengulangi? (Y/T) : ‘);
     readln(ab);
     if (ab = ‘v’) or (ab = ‘y’)then
     begin
          goto ulang;
     end
end.

^Rachmatika Irfani^

Program c++ Menghitung Nilai Kelulusan

#include <iostream.h>
#include <conio.h>
void main() {
clrscr();
float uts, uas,nil;
cout<<“====Program Kelululsan====\n”;
cout<<“==========================\n”;
cout<<” Nilai UTS : “;cin>>uts;
cout<<” Nilai UAS : “;cin>>uas;
nil = (0.7 * uts) + (0.3*uas);
cout<<” Nilai Akhir : “<<nil<<endl;
if (nil >= 60)
{
cout<<“==========================\n”;
cout<<” Selamat Anda Lulus \n”;
}
else {
cout<<” Mamam Anda Gagal\n”;
}
if (nil<=50)
{
cout<<“Grade E\n”;cout<<“Mengulang”;
}
else if (nil<=60)
{
cout<<“Grade D\n”;cout<<“Kurang”;
}
else if (nil<=75)
{
cout<<“Grade C\n”;cout<<“Cukup”;
}
else if (nil<=85)
{
cout<<“Grade B\n”;cout<<“Baik”;
}
else if (nil<=100)
{
cout<<“Grade A\n”;cout<<“Excellent”;
}
getch();
}

^Rachmatika Irfani^

Program c++ Menghitung Luas Lingkaran

#include<iostream.h>
#include<conio.h>
int main(void)
{
int r;
float L, phi=3.14;
{
cout<<“======Program Perhitungan Luas Lingkaran======\n”;
cout<< “masukan Jari-jari : “;cin>>r;
float L=phi*r*r;
cout<<“Luas Lingkaran Adalah = “<<L<<” \n”;
cout<<“tekan sembarang tombol untuk keluar….”;
}
getch();
}

^Rachmatika Irfani^

Program c++ Membuat tanda plus (+)

Berikut adalah contoh program c++ membuat tanda Plus (+) :

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr();

int i, j, n;

cout <<“Masukkan jumlah perulangan : “; cin >> n;

if (n%2)

{

for (i=1; i<=n; i++)

{

for (j=1; j<=n; j++)

{

if ((i==(n-i)+1)||(j==(n-j)+1))

{

cout <<“*”;

}

else cout <<” “;

}

cout <<endl;

} getch();

}

else

{

for (i=1; i<=n; i++)

{

for (j=1; j<=n; j++)

{

if ((i==(n/2)+1||i==(n/2))||(j==(n/2)+1||j==(n/2)))

{

cout <<“*”;

} else cout <<” “;

} cout <<endl;

} getch();

}

}

^Rachmatika Irfani^