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

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

View Full Document Right Arrow Icon
Quiz 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

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

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

View Full DocumentRight Arrow Icon
Question 3
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
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

This note was uploaded on 12/23/2011 for the course CMPT 120 taught by Professor Cuikerman during the Fall '08 term at Simon Fraser.

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 Right Arrow Icon
Ask a homework question - tutors are online