Professional Documents
Culture Documents
SKMM 1013 Sem I 2013/14: Faculty of Mechanical Engineering Universiti Teknologi Malaysia
SKMM 1013 Sem I 2013/14: Faculty of Mechanical Engineering Universiti Teknologi Malaysia
TEST 2
Name:___________________________________________
Lecturer:_________________________________________
Part A (Programming C)
Q1 /5
Q2 /5
Total /10
Q3 /3
Q4 /4
Q5 /4
Q6 /4
Total /15
This study source was downloaded by 100000760893349 from CourseHero.com on 01-29-2022 21:48:32 GMT -06:00
https://www.coursehero.com/file/74557467/SKMM-1013-Test-2-201314pdf/
Question 1 [5 marks]
The conversion factors from SI unit to USCS unit for length and mass are given by
Write a complete C program to read in the volume in m3 and mass in kg of an object. The
program should compute and display the density of the object both in kg/m3 and lb/ft3. The
conversion from kg/m3 to lb/ft3 must be computed using a programmer-defined function with
the density in kg/m3 as an input argument.
#include <stdio.h>
float deng;
deng=dsi*2.205/(3.281*3.281*3.281);
return(deng);
main()
float vol,mass,dsi;
scanf("%f %f",&mass,&vol);
dsi=mass/vol;
printf("density SI = %f\n",dsi);
system("pause");
This study source was downloaded by 100000760893349 from CourseHero.com on 01-29-2022 21:48:32 GMT -06:00
https://www.coursehero.com/file/74557467/SKMM-1013-Test-2-201314pdf/
Question 2 [5 marks]
#include <stdio.h>
main()
{
int i;
float x[]={-6,-3,-1,0,1,3,6};
float fx[7];
for (i=0;i<=6;++i)
fx[i]=x[i]*x[i]*x[i] - 2*x[i] + 5;
for (i=0;i<=6;++i)
printf("%f %f\n",x[i],fx[i]);
system("pause");
}
This study source was downloaded by 100000760893349 from CourseHero.com on 01-29-2022 21:48:32 GMT -06:00
https://www.coursehero.com/file/74557467/SKMM-1013-Test-2-201314pdf/
Question 3 [3 marks]
What are the outputs of the following MATLAB/OCTAVE commands as they would appear in the
command window?
a) x=[-5:3:5]
x= -5 -2 1 4
b) n=length([-2:4])
n=7
c) y=linspace(0,3,7)
d) a=[2 -4 0 12 5];
f=(-1)*sort(-a)
f = 12 5 2 0 -4
k=4
f) b=floor(-1.1)
b = -2
This study source was downloaded by 100000760893349 from CourseHero.com on 01-29-2022 21:48:32 GMT -06:00
https://www.coursehero.com/file/74557467/SKMM-1013-Test-2-201314pdf/
Question 4 [4 marks]
What are the outputs of the following segment of an OCTAVE/MATLAB program?
X = [1 2; 3 4];
Y = [2 -5 0; 4 0 8; -1 3 7];
a = Y(1,1:2) *X
b = find(Y(2,:))
c = X.*Y(2:3,1:2)
d = sum(Y(:,3))
a = 13 -16
b = 1 3
c = 4 0
-3 12
d = 15
This study source was downloaded by 100000760893349 from CourseHero.com on 01-29-2022 21:48:32 GMT -06:00
https://www.coursehero.com/file/74557467/SKMM-1013-Test-2-201314pdf/
Question 5 [4 marks]
The following table shows the mass and velocity for three objects.
object
1 2 3
Mass, m (kg) 5 3 8
Velocity, v (m/s) 18 22 15
m = [5 3 8];
v = [18 22 15];
This study source was downloaded by 100000760893349 from CourseHero.com on 01-29-2022 21:48:32 GMT -06:00
https://www.coursehero.com/file/74557467/SKMM-1013-Test-2-201314pdf/
Question 6 [4 marks]
Trace the following segment of an OCTAVE/MATLAB program and predict the output of the program as it
would appear in the command window.
x = [0 -3 2 -1 0 4];
n = length(x); sign_change = 0;
for j=1:n
y(j) = x(j)^2;
z(j) = sqrt(y(j));
if (z(j)~=x(j))
sign_change = sign_change + 1;
end;
end;
x - z
sign_change
y =
0 9 4 1 0 16
z =
0 3 2 1 0 4
y-z =
0 -6 0 -2 0 0
sign_change = 2
This study source was downloaded by 100000760893349 from CourseHero.com on 01-29-2022 21:48:32 GMT -06:00
https://www.coursehero.com/file/74557467/SKMM-1013-Test-2-201314pdf/
This study source was downloaded by 100000760893349 from CourseHero.com on 01-29-2022 21:48:32 GMT -06:00
https://www.coursehero.com/file/74557467/SKMM-1013-Test-2-201314pdf/
Powered by TCPDF (www.tcpdf.org)