The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
answer by C LANGAUGE Â (NOT C++ or JAVA):-
1.Â
Given that two int  variables , total and amount, have been declared , write a sequence of statements that:
After each value is read in to amount, it is added to the value in total (that is, total is incremented by the value in amount).
2.Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates , it prints out the sum of all the even integers read and the sum of all the odd integers read. Declare any variables that are needed.
3.Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates , it prints out the sum of all the even integers read. Declare any variables that are needed.
4.Write a loop that reads positiveintegers from standard input, printing out thosevalues that are even, separating them with spaces, and that terminates when it reads aninteger that is not positive.Declare anyvariables that are needed.
5.Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates , it prints out the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even integers read, and a count of the number of odd integers read, all separated by exactly one space. Declare any variables that are needed.
6.Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates , it prints out the sum of all the even integers read and the sum of all the odd integers read. Declare any variables that are needed.
7.Given that two int  variables , total and amount, have been declared , write a loop that reads non-negative values into amount and adds them into total. The loop terminates when a value  less than 0 is read into amount. Don't forget to initialize  total to 0.
8.Given an int  variable  n that has already been declared , write some code that repeatedly reads a value into n until at last a number between 1 and 10 (inclusive) has been entered.
9.Two variables , num and cost have been declared and given  values : num is an integer and cost is a double . Write a single statement that outputs  num and cost to standard output . Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character . Do not output any thing else.
10.Write a single statement that will print the message "first is " followed by the value of first, and then a space, followed by "second = ", followed by the value of second. Print everything on one line and go to a new line after printing. Assume that first has already been declared as a double and that second has been declared as an int . Assume also that the variables have already been given  values .
11.Two variables , num and cost have been declared and given  values : num is an integer and cost is a double . Write a single statement that outputs  num and cost to standard output . Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character . Do not output any thing else.
12.
The exercise instructions here are LONG -- please read them all carefully. If you see an internal scrollbar to the right of these instructions, be sure to scroll down to read everything.
Â
Given that an integer  variable  i and a floating-point variable  f have already been declared and given  values :Â
    Write a statement in C that displays the values of i and fÂ
    to standard output in the following format:
    i=value -of-i f=value -of-f
Â
Two Examples:
Example 1: if the values of i and f were 25 and 12.34 respectively, the output would be:
i=25 f=12.34
Â
Â
Example 2: if the values of i and f's value were 703 and 3.14159, (respectively) the output would be:
i=703 f=3.14159
Â
Â
Remember: you areGIVENiandf-- that means they arealreadydeclared and theyalready havevalues ! Don't change theirvalues by assigning or initializing them! Just print them out the way we have shown above. Just write onestatement to produce theoutput .
Â
Remember: you don't know what the actualvalues ofiandfare-- they are unlikely to be thevalues used in the examples above!
Â
Remember: in youroutput you must be displaying both thename of thevariable (likei) and itsvalue .
13.
Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value is considered a CONSECUTIVE DUPLICATE. In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. Note that the last 3 is not a consecutive duplicate because it was preceded by a 7.
Write some code that uses a loop to read such a sequence of non-negative integers , terminated by a negative number. When the code exits the loop it should print the number of consecutive duplicates encountered. In the above case, that value would be 3.
14.
Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value is considered a CONSECUTIVE DUPLICATE. In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. Note that the last 3 is not a consecutive duplicate because it was preceded by a 7.
Write some code that uses a loop to read such a sequence of non-negative integers , terminated by a negative number. When the code exits the loop it should print the number of consecutive duplicates encountered. In the above case, that value would be 3.
15.3.16 (Gas Mileage) Drivers are concerned with the mileage obtained by their automobiles.
One driver has kept track of several tankfuls of gasoline by recording miles driven and
gallons used for each tankful. Develop a program that will input the miles driven and
gallons used for each tankful. The program should calculate and display the miles per
gallon obtained for each tankful. After processing all input information, the programÂ
should calculate and print the combined miles per gallon obtained for all tankfuls.
Here is a sample input/output dialog:Â
Enter the gallons used (-1 to end): 12.8
Enter the miles driven: 287
The miles/gallon for this tank was 22.421875 miles.
Enter the gallons used (-1 to end): 10.3
Enter the miles driven: 200
The miles/gallon for this tank was 19.417475 miles.
Enter the gallons used (-1 to end): 5
Enter the miles driven: 120
The miles/gallon for this tank was 24.000000 miles.
Enter the gallons used (-1 to end): -1
The overall average miles/gallon was 21.601423 miles.
Note that both the gallons used and the miles driven may be decimal values .
-----------