# Thread: function call to print the smallest number?

1. ## function call to print the smallest number?

C programming, make it use a function call to print the smallest number?

hi guys
this is a program which prints out the smallest of three numbers within
the main function that I was asked to write.
Now the other question i am asked,5. Re-write the program, uses a function call to print the smallest number?
what do it mean if someone can explain or show me an example please
i am new to c

Code:
```# include <stdio.h>

main()
{
int a,b,c;
int temp, min;

a = 100;
b = 23;
c = 5;

min = a;
temp = b;
if (min < temp)
{
min = temp;
temp = c;
if (min < temp)
{
min = temp;
printf (“\nThe minimum value of these three numbers is ”, min);
}
else
{
printf (“\nThe minimum value of these three numbers is “, min);
}
}
else
{
temp = c;
f (min < temp)
{
min = temp;
printf (“\nThe minimum value of these three numbers is ”, min);
}
else
{
printf (“\nThe minimum value of these three numbers is “, min);
}
}

```

2. It's kind of difficult to give an example of this without just giving away the answer. Start by writing a function that receives the numbers declared in "main()", and move the relevant code into that function.

Based on the assignment, you should have already learned about functions, so refer to your notes for reference. You can also find information here:

Functions in C - Cprogramming.com

3. Originally Posted by Matticus
It's kind of difficult to give an example of this without just giving away the answer. Start by writing a function that receives the numbers declared in "main()", and move the relevant code into that function.

Based on the assignment, you should have already learned about functions, so refer to your notes for reference. You can also find information here:

Functions in C - Cprogramming.com

I think I got what you mean, is this right now?
but the output is below that i get, with out a number.

The minimum value is

Code:
```#include<stdio.h>

int main()
{
printf("\n The minimum value is ", minval());
}
int minval(int min)
{
int a, b, c;
int temp;

a = 100;
b = 23;
c = 5;

temp = a;
min = b;

if (temp > min)
{
temp = c;
if (temp > min)
{
min = b;
}
else
{min = temp;
}
}
else
{
min = temp;
temp = c;
if (temp > min)
{
min = b;
}
else
{
min = temp;
}
}
return min;
}```

4. Line #6, what are you missing -- look in the format section.

5. Code:
```printf("\n The minimum value is ", minval());
}
int minval(int min)```

Another problem is that you defined your function "minval" to take one argument, but in main() you call it without one.

But as I understand it your function should take three arguments and return the smallest of them.
Here are two examples for using such a function:
Code:
```int min = minval(3, 1, 2) // "min" should be 1

int a = 100, b = 23, c = 5;
int min2 = minval(a, b, c) // "min2" should be 5```
Bye, Andreas

6. Originally Posted by AndiPersti
But as I understand it your function should take three arguments and return the smallest of them.
Well, reading the first post in this thread literally, that wasn't technically a requirement. I agree with you, however, that what you describe would be an appropriate approach.

Reading the first post literally, all that is needed is to move everything within the body of main() into another function, and then call that other function from main(). If I was an instructor, however, a student who gave me that solution would fail - the purpose of programming is effective problem solving, not to see who can pedantically interpret a question to justify a response that is not "fit for purpose".