Professional Documents
Culture Documents
Name: ____SOLUTION___________________
Signature: _____________________
Student #:
_________________
Instructor: _______________
1.
2.
3.
4.
5.
Question
Max
6
5
5
4
20
10
Total
50
1
2
3
4
5
Mark
Page 2 of 7
Page 3 of 7
p
T
T
F
F
q p && q
T
T
F
F
F
T
F
F
p
T
T
F
F
q
T
F
T
F
!p
!q
!p && !q
!q
p ||!q
p || q
(p || !q) && (p || q)
Page 4 of 7
b) Convert the following decimal number into binary: 42. Show your work.
12.0
b) c / d a * b
36.0
c) a % b + b % a
d) a * d * c b / a
4.8
Page 5 of 7
Page 6 of 7
#include <stdio.h>
#include <stdlib.h>
#define GRAVITATIONAL_FORCE 9.80665
#define TRUE 1
int main( void )
{
double mass1, mass2;
double tension;
FILE* outFile;
outFile = fopen( "output.txt", "w" );
if( outFile == NULL )
{
printf( "Error opening output file\n" );
}
else
{
fprintf( outFile, "Mass 1
Mass2
Tension\n" );
while( TRUE )
{
printf( "Enter first mass: \n" );
scanf( "%lf", &mass1 );
if( mass1 == -1.0 )
break;
printf( "Enter second mass: \n" );
scanf( "%lf", &mass2 );
tension = 2 * mass1 * mass2 * GRAVITATIONAL_FORCE
/ ( mass1 + mass2 );
fprintf( outFile, "%8.3lf %8.3lf %8.3lf\n", mass1,
mass2, tension );
}
fclose( outFile );
}
system("PAUSE");
return 0;
}
Page 7 of 7
}
double foo( int a, double b )
{
printf("a = %i, b = %f\n", a, b);
a += 2;
return b 0.3;
printf("a = %i, b = %f\n", a, b);
}
36 6.1 0.0
36 6.1
36 6.1 5.8
main
a
6
36
foo
b
6.1
c
0.0
5.8
36
38
6.1