-
-
Save sunho/0ddfa516f61165e32a86e71be3d20dfd to your computer and use it in GitHub Desktop.
q3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************** | |
Exercise 1.3 | |
Rewrite the following program using optimal C coding style. | |
Pay attention to: | |
- white spaces and indentation | |
- short-cut boolean expressions in if or loop statements | |
- use the conditional operator | |
- code redundancy | |
- proper use of the relational expression in a return statement | |
- use of the comma operator in a loop | |
- use of && and || to prevent if nesting | |
Name: Sunho Kim | |
***************************************************/ | |
#include <stdio.h> | |
int findMin(int a, int b, int c, int d); | |
int main (void) | |
{ | |
int a = 10, b = 2, c = 5, d = 7; | |
printf("%d %d %d %d\n", a, b, c, d); | |
printf("The smallest value is %d\n", findMin(a, b, c, d)); | |
return 0; | |
} | |
/*************************************************** | |
Find smallest | |
PRE a, b, c, d are integers | |
POST return the smallest value | |
*/ | |
int findMin(int a, int b, int c, int d) | |
{ | |
int min = a; | |
if (min >= b) | |
min = b; | |
if (min >= c) | |
min = c; | |
if (min >= d) | |
min = d; | |
return min; | |
} | |
/** SAVE THE OUTPUT BELOW | |
10 2 5 7 | |
The smallest value is 2 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment