Difference between revisions of "CSC231 Optional Homework 9 2017"
(Created page with "--~~~~ ---- <center> <font size="+2">Page under construction!</font> </center> <P> <center> 300px </center> =Problem 1= <br /> <br /> <br /> ...") |
(→Problem 1) |
||
Line 10: | Line 10: | ||
</center> | </center> | ||
− | =Problem 1= | + | =Problem 1: C Functions= |
− | + | <br /> | |
+ | Write a '''C''' program that contains only C functions. The functions will be called by an external main program. This is very similar to the the last homework assignment, except then it was done in assembly. | ||
+ | <br /> | ||
+ | ==Functions== | ||
<br /> | <br /> | ||
+ | You have to write 3 functions: '''getMin()''', '''zap()''' and '''merge()'''. | ||
<br /> | <br /> | ||
+ | ; getMin() | ||
+ | : Receives 3 ints as parameters and returns the smallest. | ||
+ | : Example | ||
+ | ::<source lang="C"> | ||
+ | printf( "Min of -10, 1, 10 = %d\n", getMin( -10, 1, 10 ) ); | ||
+ | printf( "Min of -10, 1, 10, -20, 2 = %d\n", getMin( getMin( -10, 1, 10 ), -20, 2 ) ); | ||
+ | // outputs: | ||
+ | // Min of -10, 1, 10 = -10 | ||
+ | // Min of -10, 1, 10, -20, 2 = -20 | ||
+ | </source> | ||
<br /> | <br /> | ||
+ | ; zap() | ||
+ | : Receives two strings as parameters and modifies the first one by finding the first | ||
+ | : string in it, and replacing it with dashes. | ||
+ | : Example | ||
+ | ::<source lang="C"> | ||
+ | char s1[] = "Mississippi Burning"; | ||
+ | char s2[] = "Mississippi Burning"; | ||
+ | |||
+ | //--- test zap --- | ||
+ | printf( "s1 = %s\n", s1 ); | ||
+ | zap( s1, "ss" ); | ||
+ | printf( "zap(s1) = %s\n", s1 ); | ||
+ | |||
+ | printf( "s2 = %s\n", s2 ); | ||
+ | zap( s2, "tt" ); | ||
+ | printf( "zap(s2) = %s\n", s2 ); | ||
+ | |||
+ | // output: | ||
+ | // s1 = Mississippi Burning | ||
+ | // zap(s1) = Mi--issippi Burning | ||
+ | // s2 = Mississippi Burning | ||
+ | // zap(s2) = Mississippi Burning | ||
+ | </source> | ||
<br /> | <br /> | ||
<br /> | <br /> |
Revision as of 10:26, 22 April 2017
--D. Thiebaut (talk) 11:10, 22 April 2017 (EDT)
Page under construction!
Problem 1: C Functions
Write a C program that contains only C functions. The functions will be called by an external main program. This is very similar to the the last homework assignment, except then it was done in assembly.
Functions
You have to write 3 functions: getMin(), zap() and merge().
- getMin()
- Receives 3 ints as parameters and returns the smallest.
- Example
printf( "Min of -10, 1, 10 = %d\n", getMin( -10, 1, 10 ) ); printf( "Min of -10, 1, 10, -20, 2 = %d\n", getMin( getMin( -10, 1, 10 ), -20, 2 ) ); // outputs: // Min of -10, 1, 10 = -10 // Min of -10, 1, 10, -20, 2 = -20
- zap()
- Receives two strings as parameters and modifies the first one by finding the first
- string in it, and replacing it with dashes.
- Example
char s1[] = "Mississippi Burning"; char s2[] = "Mississippi Burning"; //--- test zap --- printf( "s1 = %s\n", s1 ); zap( s1, "ss" ); printf( "zap(s1) = %s\n", s1 ); printf( "s2 = %s\n", s2 ); zap( s2, "tt" ); printf( "zap(s2) = %s\n", s2 ); // output: // s1 = Mississippi Burning // zap(s1) = Mi--issippi Burning // s2 = Mississippi Burning // zap(s2) = Mississippi Burning