473,388 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to find and deal with maximum and minimum numbers?

Hi, I'm a C beginner.
I want to write a C.
The pseudocodes are like this:

User enters some numbers (use -1 to end)
The compiler find and delete the maximum and minimum numbers
Then average remained numbers
Finally print the result

Thanks in advance!!!
Oct 18 '08 #1
11 10228
zj******@163.com wrote:
Hi, I'm a C beginner.
I want to write a C.
The pseudocodes are like this:

User enters some numbers (use -1 to end)
The compiler find and delete the maximum and minimum numbers
Then average remained numbers
Finally print the result

Thanks in advance!!!
Do your own homework.

Homework is there to TEACH you, if you do not do it yourself
you will NOT learn anything
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Oct 18 '08 #2
zj******@163.com wrote:
Hi, I'm a C beginner.
I want to write a C.
The pseudocodes are like this:

User enters some numbers (use -1 to end)
The compiler find and delete the maximum and minimum numbers
Then average remained numbers
Finally print the result

Thanks in advance!!!
Doesn't look like pseudocode to me, mor like a (homework) task. Maybe the
following helps to get you started:

read number
counter=1
max = min = sum = number

loop
read number
counter++
if number max
max = number
else if number < min
min = number
sum += number
repeat while number not -1

sum -= (min+max)
counter -=2 /* to account for min amd max not being in anymore */
result = sum/counter
print result

Bye, Jojo
Oct 18 '08 #3
Joachim Schmitz said:
zj******@163.com wrote:
>Hi, I'm a C beginner.
I want to write a C.
The pseudocodes are like this:

User enters some numbers (use -1 to end)
The compiler find and delete the maximum and minimum numbers
Then average remained numbers
Finally print the result

Thanks in advance!!!

Doesn't look like pseudocode to me, mor like a (homework) task. Maybe the
following helps to get you started:

read number
counter=1
max = min = sum = number

loop
read number
counter++
if number max
max = number
else if number < min
min = number
sum += number
repeat while number not -1

sum -= (min+max)
counter -=2 /* to account for min amd max not being in anymore */
result = sum/counter
print result
Sorry, but I don't think that answers the OP's question. He wants the
*compiler* to find and delete the maximum and minimum numbers.

Tricky - but I suppose the obvious approach is to write a code generator
containing a hard-coded list of the answers protected by preprocessor
definitions (or, if that's not allowed, use if(0) and then switch on as
many optimisations as you can find), and then shell out to the compiler.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 18 '08 #4
Richard Heathfield wrote:
Joachim Schmitz said:
>zj******@163.com wrote:
>>Hi, I'm a C beginner.
I want to write a C.
The pseudocodes are like this:

User enters some numbers (use -1 to end)
The compiler find and delete the maximum and minimum numbers
Then average remained numbers
Finally print the result

Thanks in advance!!!

Doesn't look like pseudocode to me, mor like a (homework) task.
Maybe the following helps to get you started:

read number
counter=1
max = min = sum = number

loop
read number
counter++
if number max
max = number
else if number < min
min = number
sum += number
repeat while number not -1

sum -= (min+max)
counter -=2 /* to account for min amd max not being in anymore */
result = sum/counter
print result

Sorry, but I don't think that answers the OP's question. He wants the
*compiler* to find and delete the maximum and minimum numbers.
I believe this to be wrong wording on the OP's part.

Bye, Jojo
Oct 18 '08 #5

"Richard Heathfield" <rj*@see.sig.invalidwrote in message
Sorry, but I don't think that answers the OP's question. He wants the
*compiler* to find and delete the maximum and minimum numbers.

Tricky - but I suppose the obvious approach is to write a code generator
containing a hard-coded list of the answers protected by preprocessor
definitions (or, if that's not allowed, use if(0) and then switch on as
many optimisations as you can find), and then shell out to the compiler.
It's achieveable in C++ since templates provide a Turing-complete
meta-language. However C doesn't.
To the OP, c++ is the next newgroup.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Oct 18 '08 #6
On 10ÔÂ18ÈÕ, ÏÂÎç4ʱ27·Ö, jacob navia <ja...@nospam..orgwrote:
zj262...@163.com wrote:

Do your own homework.

Homework is there to TEACH you, if you do not do it yourself
you will NOT learn anything

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32
NO
THIS ISN'T HOMEWORK!
The homework just asks us to estimate the maximum from 10 integers.
Oct 18 '08 #7
zj******@163.com wrote:
On 10ÔÂ18ÈÕ, ÏÂÎç4ʱ27·Ö, jacob navia <ja...@nospam.orgwrote:
>zj262...@163.com wrote:

Do your own homework.

Homework is there to TEACH you, if you do not do it yourself
you will NOT learn anything

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32

NO
THIS ISN'T HOMEWORK!
The homework just asks us to estimate the maximum from 10 integers.
However: what you wrote isn't even an attempt to program something in C. Try
it, if you get stuck post what code you have and there will be people
helping you.

Bye, Jojo
Oct 18 '08 #8
zj******@163.com wrote:
>
I want to write a C. The pseudocodes are like this:

User enters some numbers (use -1 to end). The compiler find and
delete the maximum and minimum numbers Then average remained
numbers. Finally print the result
This has nothing to do with the C language. First work out the
algorithm (which is fairly simple). Then write the C code to
implement the algorithm, which is even simpler.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Oct 19 '08 #9
On 18 Oct, 09:02, zj262...@163.com wrote:
Hi, I'm a C beginner.
I want to write a C.
The pseudocodes are like this:

User enters some numbers (use -1 to end)
Why not use EOF or something that isn't a number
(for example, 'q') to terminate input?
The compiler find and delete the maximum and minimum numbers
I'm pretty sure you don't want the compiler doing that work.
Then average remained numbers
Finally print the result
Sounds like a job for printf.

Write some code. If it doesn't work, try to figure
out why. If you can't figure it out, post specific
examples and ask specific questions. Why should anyone
answer your question with more specificity than with
which it was asked?
Oct 19 '08 #10

"William Pursell" <bi**********@gmail.comwrote in message
news:67**********************************@a1g2000h sb.googlegroups.com...
On 18 Oct, 09:02, zj262...@163.com wrote:
>Hi, I'm a C beginner.
I want to write a C.
The pseudocodes are like this:

User enters some numbers (use -1 to end)

Why not use EOF or something that isn't a number
(for example, 'q') to terminate input?
Probably because dealing with an input stream consisting of numbers /or/
words is more difficult than the original assignment.

--
bartc

Oct 19 '08 #11
"Bartc" <bc@freeuk.comwrites:
"William Pursell" <bi**********@gmail.comwrote in message
news:67**********************************@a1g2000h sb.googlegroups.com...
>On 18 Oct, 09:02, zj262...@163.com wrote:
>>Hi, I'm a C beginner.
I want to write a C.
The pseudocodes are like this:

User enters some numbers (use -1 to end)

Why not use EOF or something that isn't a number
(for example, 'q') to terminate input?

Probably because dealing with an input stream consisting of numbers
/or/ words is more difficult than the original assignment.
I don't think so. Testing for some special but otherwise valid
number is more troublesome than reading numbers while there are
numbers to read:

while (scanf(...) == 1)
/* do something with the number */;

(details omitted because this is homework).

--
Ben.
Oct 19 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mr_burns | last post by:
hi, how do i do a SELECT statment that will just query a table to find the row with the maximum of a declared field. for example, if i have a table of customers and i would like to get the value...
4
by: Lobang Trader | last post by:
Hi all, I am trying to create a username and a password class. I would like to know what are the RECOMMENDED minimum and maximum length for both fields? These fields will be something like...
2
by: Hennie de Nooijer | last post by:
I have a problem (who not?) with a function which i'm using in a view. This function is a function which calculates a integer value of a date. For example: '12/31/2004 00:00:00" becomes 20041231....
2
by: Hennie de Nooijer | last post by:
Because of an error in google or underlying site i can reply on my own issue. Therefore i copied the former entered message in this message....
2
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the...
21
by: Imran | last post by:
I have a vector of integers, such as and I want to find out the number which occurs most frequently.what is the quick method. My array size is huge. what I am doing is 1. find out the...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
18
by: Rose4msm | last post by:
hello can any one please help me i have a test and i need to study the java scripts, i know that i have to use arrays but im still a bit confuse the question is to ask the user how many data items...
5
by: NoOoR | last post by:
I want to write a program that read n numbers and perform some mathematical tasks on them. The task available for the user is as follow : 1- Finding the average 2- Find the maximum...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.