G Parabola: 'Masukan Jumlah Angka ' 'Masukan Angka '
G Parabola: 'Masukan Jumlah Angka ' 'Masukan Angka '
G Parabola: 'Masukan Jumlah Angka ' 'Masukan Angka '
clc;clear;
n=input('masukan jumlah angka = ');
for i=1:1:n
x(i)=input('masukan angka = ');
end
fprintf('\n')
fprintf('\n')
disp(x)
G Parabola
clc;clear;
Vo=input('Vo = ');
Xo=input('Xo = ');
Yo=input('Yo = ');
Xt=input('Xt = ');
Yt=input('Yt = ');
Ht=input('Ht = ');
a=input('a = ');
t=(Xt-Xo)/Vo/cos(degtorad(a));
yot=Yo+Vo*sin(degtorad(a))*t-10*(t^2)/2;
if yot>= Yt-Ht/2 && yot<=Yt+Ht/2
fprintf('target kena\n')
else
fprintf('miss\n')
end
tplot=0:0.001:t;
yplot=Yo+Vo*sin(degtorad(a))*tplot-10*(tplot.^2)/2;
plot(tplot,yplot); hold on
yy=Yt+Ht;
yyy=Yt:0.0001:yy;
plot(Xt,yyy,'r');
hold off
%program ini mengurutkan ulang array yang
%diinput mulai dari yang selisihnya terkecil
%dari rata-rata data dalam array tsb
%contoh:
%input [1 2 3 4 5]
%output [3 2 4 1 5]
clc;clear;
data=input('inputkan array= ');
rata2=mean(data)
selisih=abs(data-rata2)
for i=1:length(data)-1
for j=i+1:length(data)
if selisih(i)>selisih(j)
a=data(i);
b=data(j);
data(i)=b;data(j)=a;
c=selisih(i);
d=selisih(j);
selisih(i)=d;selisih(j)=c;
end
end
end
data
Write File
a=input('Nama file input(termasuk.txt) :','s');
[x,y,z]=textread(a,'%d %d %d',4,'headerlines',2);
v=x.*y.*z;
l=2*(x.*y+x.*z+y.*z);
r=4*(x+y+z);
b=input('nama file output(termasuk.txt) :','s');
c=fopen(b,'w');
fprintf(c,'data hasil perhitungan\n');
fprintf(c,'R(cm) L(cm2 ) V(cm3)\n');
for i=1:length(x)
fprintf(c,'%5.2f %6.2f %6.2f\n',r(i),l(i),v(i));
end
fclose(c);
Bakso
clear;clc;
i=0;
total=0;
nilai=0;
while nilai~=9999
i=i+1;
nilai=input('nilai data = ');
total = nilai + total;
end
total = total - 9999;
i=i-1
rata=total/i;
fprintf('\n')
fprintf('total nilai = %d\n',total)
fprintf('jumlah data = %d\n',i)
fprintf('rata-rata data = %d\n',rata)
FPB KPK
a=input('masukan angka: ');
b=input('masukan angka: ');
c=gcd(a,b);
d=lcm(a,b);
fprintf('fpb= %d\n',c)
fprintf('kpk= %d\n',d)
clc;clear;
a=input('a= ');
b=input('b= ');
i=1;
while mod(a*i,b)~=0
i=i+1;
end
kpk=a*i
%cari fpb
if a<b
c=a;
else
c=b;
end
for i=1:c
if mod(a,i)==0 & mod(b,i)==0
fpb=i;
end
end
fpb
clc;clear;
fprintf('Guessing Games 1-100\nWith 15 Chance to Guess the correct Number\n');
Chance=15;
Turn=1;
Score=100;
%rn=Real Number;
rn=rand(1);
rn=100*rn;
rn=ceil(rn);
fprintf('I am Thinking a Number between 1 to 100\n');
guess=input('Guess that Number : ');
while guess~=rn
Distance=abs(guess-rn);
if Distance>50
fprintf('Your Guess is Too Far\n');
elseif Distance>30
fprintf('Your Guess is Still Far\n');
elseif Distance>15
fprintf('Your Guess is Not to Far\n');
elseif Distance>10
fprintf('Your Guess is Nearly Close\n');
elseif Distance>5
fprintf('Your Guess is Almost Close\n');
elseif Distance>=1
fprintf('Your Guess is Very Close\n');
end
Chance=Chance-1;
fprintf('Your Chances Left : %d\n',Chance);
if Chance==0
break
end
Turn=Turn+1;
guess=input('Guess Another Number : ');
fprintf('\n');
if Chance<=10
Score=Score-10;
end
end
if Chance==0
fprintf('You Failed.. Please Try Again\n');
fprintf('Your Score is %d',Score);
else
fprintf('Congratulations! You guessed the Correct Number in %d Turn and
Still Have %d Chances \n',Turn,Chance);
fprintf('Your Score is %d\n',Score);
INDLG
clear;clc;lagi=1;
prompt={'b (mm)','h (mm)'};
dlgTitle='INPUT DATA';
def={'300','400'};
lineNo=1;
lagi=1;
while lagi==1
answer=inputdlg(prompt,dlgTitle,lineNo,def);
data=str2num(char(answer));
b=data(1)
h=data(2)
A=b*h
def={num2str(data(1)),num2str(data(2))};
lagi=input('input lagi? [1]ya [0]tidak :');
end
clear;clc;
for a1=123:329
a2=2*a1;
a3=3*a1;
astr=[num2str(a1),num2str(a2),num2str(a3)];
for i=1:9
A(i)=str2num(astr(i));
end
status=1;
for i=1:8
for j=i+1:9
if A(i)*A(j)==0 || A(i)==A(j)
status=0;
end
end
if status==0
break;
end
end
end
if status==1
A
end
text(x1,y1,'Tipot 1')
text(x2,y2,'Tipot 2')
fprintf('M = %d t\n',M)
x=input('Masukan Jarak Potong = ');
if x>l
Nx=0;
Da=(b*(x-l))/x;
Dx=b-Da;
Mx=(Da*x)-b*(x-l);
fprintf('Nx = %d t\n',Nx)
fprintf('Dx = %d t\n',Dx)
fprintf('Mx = %d t\n',Mx)
end
Nx=0;
Dx=(b*((p-x)-(l-x))/(p-x));
Dka=b-Dx;
Mx=Dka*(p-x)-Dx*(l-x);
fprintf('Nx = %d t\n',Nx)
fprintf('Dx = %d t\n',Dx)
fprintf('Mx = %d t\n',Mx)
%2
clear;clc;
fprintf('Keterangan: a^b=c atau alogc=b\n')
a=input('a=');
c=input('c=');
format short
b= (log (c))/(log (a))
%Studio Bahasa Pemrograman
%Praktikum 9
%Richard Antoni Gosno / Nrp :21413042
clc;clear;
datafile=input('Masukkan Nama File (Including .txt) : ','s');
[l w h tf tw]=textread(datafile,'%d %d %d %d %d',7,'headerlines',2);
for i=1:length(l)
l(i)=l(i)*1000;
w(i)=w(i)*1000;
h(i)=h(i)*1000;
tw(i)=tw(i)*10;
la(i)=l(i)-2*tw(i);
wa(i)=w(i)-2*tw(i);
ha(i)=h(i)-tf(i);
va(i)=(la(i)*wa(i)*ha(i))*10^-9;
vb(i)=((l(i)*w(i)*h(i))-va(i))*10^-9;
vt(i)=(10/100)*vb(i);
jk(i)=ceil((l(i)*w(i))+(2*l(i)*h(i))+(2*w(i)*h(i))+((l(i)*w(i))-(la(i)*wa(i)))
+(la(i)*wa(i))+(2*la(i)*ha(i))+(2*wa(i)*ha(i)))/90000;
end
Tandon:
w(m) h(m) tf(mm)
1
1
5
1
1
6
1
1
7
2
1
8
2
2
10
3
2
11
4
3
15
tw(cm)
10
12
15
17
20
22
30