{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cmpt130quiz2

# cmpt130quiz2 - What does the printf statement shown below...

This preview shows pages 1–8. Sign up to view the full content.

Quiz 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Question 1 What is -1010 in 5 bit 2’s complement notation? First determine what -102 is It’s 1010 (1 * 8 + 0 * 4 + 1 * 2 + 0 * 1) Pad it with zeroes to 5 bits: 01010 Then flip the bits 01010 flipped is 10101 And finally add 1 10101 + 1 = 10110
Informal Conversion Algorithm Say you want to convert 70110 to binary Find the largest power of 2 that 701 is divisible by It’s 512 (1,2,4,8,16,32,64,128,256,512,1024,2048,. ..) Write down 1 Subtract 512 from 701 = 189 Go through the lower powers of 2 one by one If the power of 2 is less than the number repeat

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example 701 – 512 = 189 1 256 > 189 10 189 – 128 = 61 101 64 > 61 1010
Question 2 What do the printf statements shown below print? int x = 7; x--; printf( “%d” ,x); 6 printf( “%d” , 20 / 3 ); 6

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Question 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: What does the printf statement shown below print? if(3 > -7 && 12 < 15) printf( “true” ); else printf( “false” ); ▪ false Question 4 Write a complete program that prompts the user to enter two numbers and that prints the remainder of the first divided by the second. #include “stdio.h” int main() { int dividend, divisor; printf( “Please enter the dividend: ” ); scanf( “%d” , &dividend); printf( “Please enter the dividend: ” ); scanf( “%d” , &divisor); printf( “remainder = %d” , dividend % divisor); return 0; } Question 5 Write a function to return 1 if its single integer parameter is even, and 0 otherwise int even( int x) { if(x % 2 == 0){ return 1; }else{ return 0; } }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

cmpt130quiz2 - What does the printf statement shown below...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online