Hw 5 Solution .docx

# Hw 5 Solution .docx -...

• Homework Help
• 5

This preview shows 1 out of 5 pages.

#include "stdio.h" #include "string.h" #include "stdlib.h" typedef struct Person{ char name[20]; int age; int score; } Person; void hw5_1(); void hw5_2(); void hw5_3(); int main(void){ hw5_1(); hw5_2(); hw5_3(); } void printString(char str[]); void computeMinMax(double arr[],int length,double * min,double * max); void hw5_1(){ char s[] = "I like homework";

Subscribe to view the full document.

printString(s); printf("\n"); double arr[] = {1,-1.1,40,50,3,3,2,3}; double min,max; computeMinMax(arr,8,&min,&max); printf("min: %lf max: %lf\n",min,max); } void printString(char s[]){ while(*s != 0){ printf("%c",*s); s++; } } void computeMinMax(double arr[],int length,double * min,double * max){ if(length <= 0) return; (*min) = arr[0]; (*max) = arr[0]; for(int i = 0; i < length;i++){ if((*min) > arr[i]) (*min) = arr[i]; if((*max) < arr[i]) (*max) = arr[i];
} return; } Person createPerson(char name[],int age,double score); void printPerson(Person p); void changeAge(Person * p,int newAge); void printPeople(Person people[],int length); void savePerson(char fileName[],Person p); void hw5_2(){ Person p = createPerson("Rickard",31,100); printPerson(p); changeAge(&p,30); printPerson(p); Person people[3]; people[0] = createPerson("John",22,83); people[1] = createPerson("Danny",24,63); people[2] = createPerson("Marry",20,81);

Subscribe to view the full document.

You've reached the end of this preview.
• Fall '08
• Staff
• person, Return statement, Void type, fptr

{[ 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