ch04 - Chapter 4 Exercises Solutions 4.1 int power (int x,...

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

View Full Document Right Arrow Icon
Chapter 4 Exercises Solutions 4.1 int power (int x, char n) { int prod, i; prod = 1; if (x == 1 || n == 0) return 1; else { for (i = 1; i <= n; i++) prod = prod * x; } return prod; } 4.2 /* count blanks, digits, letters, newlines, and others. */ void count_char (char *c) { int blank_cnt = 0, digit_cnt = 0, letter_cnt = 0, nl_cnt = 0, other_cnt = 0; while (!(*c)) { if (*c == ‘ ‘) ++blank_cnt; ++digit_cnt; ++letter_cnt; else if (*c == ‘\n’) ++nl_cnt; else ++other_cnt; c++; } printf(“%10s%10s%10s%10s%10s\n\n”,“blanks”,“digits”,“letters”,“lines”,“others”); printf(%10d%10d%10d%10d%10d\n\n”,blank_cnt,digit_cnt,letter_cnt,nl_cnt, other_cnt); } 4.3 int test8 (int x) { if (!(x % 8)) return 1; else return 0; } 4.4 int gcd (int m, int n) 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
{ int i, limitj, temp; if (m == 1 || n == 1) return 1; if (m >= n) limit = n; else limit = m; temp = 1; for (i = 2; i <= limit; i++)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/12/2011 for the course EEL 4742 taught by Professor Weeks during the Spring '11 term at University of Central Florida.

Page1 / 4

ch04 - Chapter 4 Exercises Solutions 4.1 int power (int x,...

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

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