Você está na página 1de 2

input Script

clc
r=input('Enter the radius of acetylene bottle in meters');
h=input('Enter the height of cylindrical part of acetylene bottle in meters');
V_top=(2*pi*r^3)/3;
V_cyl=pi*r^2*h;
V_tot=V_top+V_cyl

Command
Enter the radius of acetylene bottle in meters 0.3
Enter the height of cylindrical part of acetylene bottle in meters 1.5

V_tot =

0.4807

disp Script
clc
disp('This script computes the volume of an acetylene bottle')
disp(' ')
r=input('Enter the radius of acetylene bottle in meters');
h=input('Enter the height of cylindrical part of acetylene bottle in meters');
V_top=(2*pi*r^3)/3;
V_cyl=pi*r^2*h;
V_tot=V_top+V_cyl;
disp(' ')
disp('The volume of the acetylene bottle is ')
disp(V_tot)

Command
This script computes the volume of an acetylene bottle

Enter the radius of acetylene bottle in meters 0.3


Enter the height of cylindrical part of acetylene bottle in meters 1.5

The volume of the acetylene bottle is


0.4807
str Script
clc
disp('This script computes the volume of an acetylene bottle')
disp(' ')
r=input('Enter the radius of acetylene bottle in meters');
h=input('Enter the height of cylindrical part of acetylene bottle in meters');
V_top=(2*pi*r^3)/3;
V_cyl=pi*r^2*h;
V_tot=V_top+V_cyl;
disp(' ')
str=['The volume of the acetylene bottle is ',num2str(V_tot),' cubic meters'];
disp(str)

Command
This script computes the volume of an acetylene bottle

Enter the radius of acetylene bottle in meters 0.3


Enter the height of cylindrical part of acetylene bottle in meters 1.5

The volume of the acetylene bottle is 0.48066 cubic meters

fprintf Script
clc
disp('This script computes the volume of an acetylene bottle')
disp(' ')
r=input('Enter the radius of acetylene bottle in meters');
h=input('Enter the height of cylindrical part of acetylene bottle in meters');
V_top=(2*pi*r^3)/3;
V_cyl=pi*r^2*h;
V_tot=V_top+V_cyl;
disp(' ')
str=['The volume of the acetylene bottle is ',num2str(V_tot),' cubic meters'];
disp(str);
fo=fopen('output.txt','w');
fprintf(fo,'The radius of acetylene bottle: %g meters\n', r);
fprintf(fo,'The height of cylindrical part of acetylene bottle: %g meters\n', h);
fprintf(fo,'The volume of acetylene bottle: %g meters\n', V_tot);
fo=fclose(fo);
Command

loop Script
clc
fprintf('x cos(x)\n')
fprintf('-------------------\n')
x=-pi;
while x<=pi
y=cos(x);
fprintf('%8.3f %8.2f \n',x,y);
x=x+pi/4;
end
Command
x cos(x)
-------------------
-3.142 -1.00
-2.356 -0.71
-1.571 0.00
-0.785 0.71
0.000 1.00
0.785 0.71
1.571 0.00
2.356 -0.71
3.142 -1.00

diary

Você também pode gostar