C By Discovery (4th Edition)

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

View Full Document Right Arrow Icon
CSE 1320 – Section 001 Midterm 1 (Practice B) Name:_____________________________________________________Grade: ___________ [100pts] 1. Predict the output of the program below that uses increment operators and precedence. Write the output in the spaces below. Write one character per space. Indicate end of lines with the symbol ‘\n’. [10pts] int a, x, y; __________12_\n__________ x = y = 2; __________27_\n__________ x = ++y; _________________________ printf(“%d\n”, 3*x+ y--); _________________________ a = 5*(x++) – 2*x; _________________________ printf(“%d\n”, a * ++y); 2. Write a function gcd(int x, int y) to find the greatest common divisor for the integers x and y such that x, y > 0. The function should return an integer. Your code should contain the heading, declarations, blocks, and statements necessary. [10pts] int gcd(int x, int y) { while (y > 0) { x = y; y = (x % y); } return x; } 3. Implement the power function power(int x, int n) without using the pow function or the multiplication operation. With regards to arithmetic operations, you are allowed to use only addition and compound assignment. The function returns the integer value x
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/06/2011 for the course CSE 1320 taught by Professor Sprintston during the Spring '08 term at UT Arlington.

Page1 / 4

Practice1B - CSE 1320 Section 001 Midterm 1(Practice B...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online