answersLogoWhite

0


Best Answer

Since this is likely a homework question, what will be provided here instead of code is information that you can use to write the code. (Half of the fun of programming is the problem solving and associated trouble shooting.)

Firstly, you need to know what kind of interface the application uses: console or graphical. That'll help you determine how you'll receive the information from the user (input) and how you're displaying the results (output).

Secondly, you know that you need comparison operators and a for() loop. Since "n" is the number of values you'll accept from the user, and say "c" is the counter value, your loop will look something like: for (c=0; c<n; c++) { [your code here] }

Then you'll need four additional variables:

- one to accept the user's data;

- one to store the number from the user;

- one to store the largest value;

- one to store the smallest value.

Be sure to initialise the largest value to the smallest number you can store, and the least value to the largest number you can store. I don't know which type you're instructed to use, but for a 32-bit "int" you're looking at a range of -2,147,483,647 to 2,147,483,648.

Also, the reason you need two variables for storing the user's inputs is because the user might enter non-numeric data. So store the user's input in a char[] array, then use atoi() to convert that into an integer, and you'll be able to avoid any problems with types since atoi() ignores everything after and including the first non-digit character.

Once you've got that number, compare it with the current largest value - if the user's number is greater, set the largest value to that number. If the user's number is lower than the least number, set the least number to that value.

Once the loop is finished, simply display the results, and you're done!

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in c language using while loop to accept n numbers and find then print largest and least number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a c program to accept a numbers and generate square root cube and exponential values?

write a c program to accept a number and generate a square root cube and exponential values


Write a program in 'C' language to accept 6 strings as input and print them in lexicographic?

(ab)*b


Draw a flowchart to accept 3 numbers and display the largest number?

draw a flowchart to display the first tenth even number


Write a program to accept 2 numbers and tell whether the product of the two number is equal to or greater than 1000?

C programm


Accept 5 numbers in an array and display it?

Accept 5 numbers in an array and display it.


Write a program in COBOL to find the largest of N number?

identification division. program-id. greatest. environment division. data division. working-storage section. 77 a pic 999. 77 b pic 999. 77 c pic 999. procedure division. greatest. display "ENTER THE THREE NUMBERS:". accept a. accept b. accept c. if a &gt; b and a &gt; c display a "is greatest" else if b &gt; c display b "is greatest" else display c "is greatest". display " thank you". stop run.


In eztrieve language how do you accept the current date?

ACCEPT DATE [YYYYMMDD] This will do it


How can you accept sum and print numbers without creating variables?

It is very easy. The program begins here..... /*Program to sum and print numbers without creating variables*/ #include&lt;stdio.h&gt; main() { clrscr(); printf("%d+%d=%d",5,2,5+2); getch(); } /*Program ends here*/ Now just by changing the numbers in the "printf" statement we can add, subtract, multiply and divide the numbers without using variables. Hence the problem is solved..........


Draw a flowchart that will determine and display the largest among the three numbers being inputted?

start input A &amp; B if A&gt;B print A is greatest if B&gt;A print B is greatest stop james ola writes.....SOT.


Will nyu accept American sign language as a language?

Yes, NYU does accept American Sign Language as a language that fulfills their language proficiency requirement. Students can demonstrate proficiency in ASL through placement tests or official certification.


Write the program in qbasic and add two numbers?

Cls input "enter two no.s ",a,b sum=a+b print "sum = ";sum end


A flowchart to Accept three numbers and check whether it firms to Pythagorean triplet?

Accept 3 natural numbers and check whether it firms pythagorean triplet