{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw6_solution

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

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

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

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

View Full Document
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
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];

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern