Question

Write a C – program that calls a user-defined function from within main() that determines the...

Write a C – program that calls a user-defined function from within main() that determines the minimum value from three

positive numbers received from the user. Your function should be called minimum.  You must use a loop to receive the numbers.

If the user enters a negative number, you must ask the user to re-enter the number.

The function should also print out the positive numbers and the smallest number.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

#include<stdio.h>

int minimum(int a,int b,int c);

int main()

{

int i,array[100],a,b,c,d;

printf("enter the array elements:\n");

for(i=0;i<3;i++)

{

scanf("%d",&array[i]);

if(array[i]<0)

{

i--;

printf("please enter postive number: ");

}

}

a=array[0];b=array[1];c=array[2];

printf("positive numbers :%d %d %d\n",a,b,c);

d=minimum(a,b,c);

printf("minimum number: %d ",d);

}

int minimum(int a,int b,int c)

{

if(a<b && a<c)

return a;

else if(b<a && b<c)

return b;

else

return c;

}

Add a comment
Know the answer?
Add Answer to:
Write a C – program that calls a user-defined function from within main() that determines the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ program Exercise #1: Index of the Minimum Write a function main() that prompts the user...

    c++ program Exercise #1: Index of the Minimum Write a function main() that prompts the user to input a positive integer n, then calls the function generate() which generates n random numbers in the range [11, 217] inclusive. The function main() also calls the function indexMin() which finds the smallest random number and its index. The function main() prints the random numbers and the two values produced by the function indexMin(). Sample input/output: How many integers: 9 The 9 random...

  • Write a program that calculates the average of a stream of non-negative numbers. The user can...

    Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...

  • Q.1. Write a C program that determines whether a line entered by a user is a...

    Q.1. Write a C program that determines whether a line entered by a user is a palindrome or not. You must demonstrate it as an application of stack (you may use linked list implementation demonstrated in the class). Hint! Think of the basic property of a stack i.e. LIFO (list-in-first-out). Q.2. Write a charQueue header file containing all the function headers of following functions: 1- initiateQueue—to initialize a queue 2- enqueue—to add a node at the rear end of the...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • Help. Write a C++ program that determines which of a company's four divisions (North, South, East,...

    Help. Write a C++ program that determines which of a company's four divisions (North, South, East, West) has the greatest sales for the quarter. It should include three functions at a minimum: float getSales() is passed the name of a division. It asks the user for a division's quarterly sales figure, calls a validate() function that will validate the input, and then returns the value back to main(). This function should be called once for each division. void validate() is...

  • Write a program that will do the following. The main function should ask the user how...

    Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...

  • Write a C++ program using user defined functions that will read in the lengths of two...

    Write a C++ program using user defined functions that will read in the lengths of two side of a right triangle and then calculate the length of the hypotenuse. The program should do this twice. The program should the following user defined functions: Function readA will read in a value for side A from the user and return it to main. (it will not receive any input data from main) Function readB will read in a value for side B...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • Assignment Content PROGRAM DESCRIPTION Make a program that will allow the user to select a choice...

    Assignment Content PROGRAM DESCRIPTION Make a program that will allow the user to select a choice from the following options: A-getCount B-getSum C-checkNum D-getFactorial X - Exit Each options (A,B,C) must have its own user-defined function. The program must repeat the program until the user enters "X". Options are: 1. getCount. The module is designed to encode numbers until user enters "x" and determine the number of positive and negative numbers of the encoded numbers within the module. 2. getSum....

  • white a program that determines if 3 numbers that are entered, by the user, are sides of a right triangle.

     project 5 functions calling functions white a program that determines if 3 numbers that are entered, by the user, are sides of a right triangle. remember any combination of numbers can be entered, 3 4 5, 5 4 3, 4 3 5... are all the same right triangle. you must have a function that does exponentiation, one that does input one that does output. and one that does the comparisons the main will be this code main:    jal allwork    li $v0,10    syscall function allwork will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT