C programming Question Please help?

Home » Programming & Design » C programming Question Please help?
Programming & Design No Comments

Please write me a c program containing this

Write a program that reads 1000 values
Discards to smallest , and discards two smallest
And get the average of the remaining

Print out the discarded values and the average of the remaining numbers

Best Answer:

tariq: //create an array to hold 1,000 values

//loop loop through the array and find
//the smallest and second smallest values

//get the index of the smallest value
//get the index of the 2nd smallest value

//remove values at the two above indexes from the array

//compute the average of remaining values in the array

//print the average

Please follow the pseudo code code above to create your program.
Reseach on how each individual pseudo code can be implemented.

That way you will learn on your own and developer some trouble shooting knowledge along the way.

Other answer:

tariq:
Write your own version and ask for help with specific problems in your code. That way we might be able to understand what "Discards to smallest , and discards two smallest" is supposed to mean.

Update: (with some pseudo code)

sum = 0
small1 = large value
small2 = large value
count = 0

start loop (1000 times)
read number
add number to sum

if number < small1 OR number < small2 then
if small1 < small2 then
small2 = number
else
small1 = number
end if (second if)
end if (first if)

increment count by 1
end loop

subtract both small1 and small2 from sum
subtract 2 from count
average = sum divided by count

output small1, small2, average

This does not require an array or reading numbers more than once.

Now convert this to C.

Mark:
write your own version and ask for help with specific problems in your code… that way we might be able to understand what "discards to smallest , and discards two smallest" is supposed to mean…

update: (with some pseudo code)

sum = 0
small1 = large value
small2 = large value
count = 0

start loop (1000 times)
read number
add number to sum

if number &lt; small1 or number &lt; small2 then
if small1 &lt; small2 then
small2 = number
else
small1 = number
end if (second if)
end if (first if)

increment count by 1
end loop

subtract both small1 and small2 from sum
subtract 2 from count
average = sum divided by count

output small1, small2, average

this does not require an array or reading numbers more than once…

now convert this to c…

Tommaso:
//create an array to hold 1,000 values

//loop loop through the array and find
//the smallest and second smallest values

//get the index of the smallest value
//get the index of the 2nd smallest value

//remove values at the two above indexes from the array

//compute the average of remaining values in the array

//print the average

pleease follow the pseudo code code above to create your program…
reseach on how each individual pseudo code can be implemented…

that way you shall learn on your own and developer some trouble shooting knowledge along the way…

Andy T:
If you expect answer without first working out for it proper, you might as well drop out and shift to easier academic discipline.
Ernesto:
and how do 'you' learn if you don't practice or have a go ?

at least try to do it
then post your work on pastebin

or better ideone (you can run you code there – choose the language from the drop down)

add your link to your question, and get comments

meanwhile …… …i assume you have a reference book or have seen some 'learn c' youtubes or similar

Andi:
and how do 'you' learn if you don't practice or have a go ?

At least try to do it
then post your work on pastebin
http://pastebin.com/

or better ideone (you can run you code there – choose the language from the drop down)
https://ideone.com/

Add your link to your question, and get comments

Meanwhile .. .I assume you have a reference book or have seen some 'learn c' Youtubes or similar

joe:
Help does not mean for someone to do it for you! So show us your work, and explain where you are stuck!
Muhammad Anas:
I think you have to use loops and if else statement in this question.
Duncan:
What help do you need?

LEAVE A COMMENT