hw6_solution

hw6_solution - EME5 Homework 6 Solutions November 5, 2010 3...

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

View Full Document Right Arrow Icon
EME5 Homework 6 Solutions November 5, 2010 3 Chapter 10, Problem 1 Change %f to %d for int type argument in print statement. 4 Chapter 10, Problem 2 4.1 Part a str needs a minimum length of 6; one element for each letter in hello and an element for the terminating NULL character. 4.2 Part b printf(%d %d %d\n, a[0], a[1], a[2]); 4.3 Part c Too many initializers declared. double f[3] = 1.1, 10.01, 100.01; 4.4 Part d d[1][9] = 2.345; 5 Chapter 10, Problem 8 5.1 Solution Code #include<stdio.h> int compare(double a[], double b[], int npts) { int i; int retval; 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
for(i = 0; i < npts; i++) { if(a[i] == b[i]) retval = 1; else { retval = 0; i = npts; } } return retval; } int main() { int a[4] = {1, 2, 3, 4}, b[4] = {1, 3, 4, 5}; printf("compare arrays a & a: %d\n", compare(a, a, 4)); printf("compare arrays a & b: %d\n", compare(a, b, 4)); return 0; } 5.2 Solution Output compare arrays a & a: 1 compare arrays a & b: 0 6 Chapter 10, Problem 22 6.1 Part b.1 6.1.1 Solution Code #include <stdio.h> #define N 7 int main() { int a[N] = {1, 4, 6, 4, 9, 5, 12}; int i, j, temp; int total=0; double mean, median; printf("The original data:\n"); for(i = 0; i < N; i++) { total += a[i]; 2
Background image of page 2
printf(" %d", a[i]); } mean = (double)total/N; for(i = 0; i < N-1; i++) { for(j = i+1; j < N; j++) { if(a[i] > a[j]) { temp = a[i]; a[i] = a[j];
Background image of page 3

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

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

This note was uploaded on 04/23/2011 for the course EME 5 taught by Professor Staff during the Fall '08 term at UC Davis.

Page1 / 8

hw6_solution - EME5 Homework 6 Solutions November 5, 2010 3...

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

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