/* declare function Largest: */
/* The function takes 3 integers as parameters and returns the largest */
int Largest (int first, int second, int third);
/* now define the function */
int Largest (int first, int second, int third)
{
int answer; /* answer will be the largest we find */
answer = first; /* assume the first is the largest */
if (second > answer) /* if the second number is larger */
answer = second; /* then update the answer */
if (third > answer) /* now look at the third number */
answer = third; /* update the answer if we found a greater one */
return answer; /* return the answer to the caller */
} /* main */
/* A test main to show this works */
#include <stdio.h>
int main()
{
int solution; /* temporary answer from a call */
/* Call the function with various sets of test data */
solution = Largest (10,20,30); /* find the largest number */
printf ("Largest is %i\n", solution
); /* print the answer */
solution = Largest (5, 10, 6); /* another test case */
printf ("Largest is %i\n", solution
); /* print the answer */
return 0; /* exit */
}
LyogZGVjbGFyZSBmdW5jdGlvbiBMYXJnZXN0OiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqLwovKiBUaGUgZnVuY3Rpb24gdGFrZXMgMyBpbnRlZ2VycyBhcyBwYXJhbWV0ZXJzIGFuZCByZXR1cm5zIHRoZSBsYXJnZXN0ICovCgppbnQgTGFyZ2VzdCAoaW50IGZpcnN0LCBpbnQgc2Vjb25kLCBpbnQgdGhpcmQpOwoKLyogbm93IGRlZmluZSB0aGUgZnVuY3Rpb24gKi8KCmludCBMYXJnZXN0IChpbnQgZmlyc3QsIGludCBzZWNvbmQsIGludCB0aGlyZCkKewogICAgaW50IGFuc3dlcjsgICAgICAgICAgICAvKiBhbnN3ZXIgd2lsbCBiZSB0aGUgbGFyZ2VzdCB3ZSBmaW5kICovCgogICAgYW5zd2VyID0gZmlyc3Q7ICAgICAgICAvKiBhc3N1bWUgdGhlIGZpcnN0IGlzIHRoZSBsYXJnZXN0ICovCgogICAgaWYgKHNlY29uZCA+IGFuc3dlcikgICAvKiBpZiB0aGUgc2Vjb25kIG51bWJlciBpcyBsYXJnZXIgKi8gCiAgICAgICAgYW5zd2VyID0gc2Vjb25kOyAgIC8qIHRoZW4gdXBkYXRlIHRoZSBhbnN3ZXIgKi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