Friday, July 31, 2009

How to Write a C program with a loop that asks user to enter a series of integers in the range of [-100 100].?

How to Write a C program with a loop that asks user to enter a series of integers in the range of [-100 100]. If user enters a number out of that range, your program shouldn’t consider it, and should ask for a new number. The user should enter 0 to stop the loop. When the loop stops, we want your program to display


• the largest TWO numbers entered in the range of [-100 100],


• the smallest TWO numbers entered in the range of [-100 100],


• the average of negative numbers entered in the range of [-100 100], and


• the average of positive numbers entered in the range of [-100 100].





For example if user enters -2 3 -4 -200 5 -3 120 0


Your program should print:


• Two largest numbers are: 5 3


• Two smallest numbers are: -4 -3


• Average of negative values is -3


• Average of positive values is 4

How to Write a C program with a loop that asks user to enter a series of integers in the range of [-100 100].?
Your loop will be a while loop





anwer = -999;


while (answer!=0)


{


ask user for answer


if(answer%26lt;100 and answer%26gt;-100)


{


if(answer%26lt;smallest)


smallest = answer


if(answer%26gt;largest)


largest=answer


}


}
Reply:#!/bin/c





public static void main(String[] args){


10:


a=rails.framework.inputLoop(-100,100);


print b;


goto 10


end;


}
Reply:You should at least try to do your own homework before asking for someone to do it for you. Give it a try, and ask questions about what you don't understand.

floral bouquets

No comments:

Post a Comment