Question

In: Computer Science

Questions: 1) // declare integer variable sum equal to zero // declare variable integer i //...

Questions: 1) // declare integer variable sum equal to zero // declare variable integer i // declare while loop condition where i is less then 25 // inside of brackets calculate the sum of i (addition) // increment i // outside the loop print the sum of values =============================================

2) Create a sentinel value example if I press number 0 it will display the sum of data // create a scanner // prompt the user to to enter the numbers // declare variable integer and relate that to input scanner // declare variable sum equals to zero // declare while loop condition where the variable you just created above is not equal to 0 // inside of the bracket of while condition sum the data with addition // prompt the user to enter integer unless its not zero // again the same variable that you created outside the while condition will ask to input value through scanner // outside the bracket display the sum of values

3) Declare the do while loop // declare the variable integer which is equal to zero // declare do-while loop and inside of brackets prompt the user to print word "Hello" // increment the variable integer that you declared outside the loop // outside brackets declare while condition where variable that you declared in the beginning is less then 25

4) Continue the same process as exercise number 3, but this time use for loop

5) Create break command in while loop // declare integer variables sum and number and both of them are equal to zero // create while condition where number is less then 25 // inside of brackets increment number // declare if condition where number is equal to 10 // write continue ++ // sum the number (addition) // outside of brackets display sum in console

6) In this exercise do the same thing like number 5 exercise but instead of continue ++ write break;

Solutions

Expert Solution

We have declared int sum = 0, Then with the help of while loop, we are going on adding the value of i from 0 to 24, using the condition while(i<25).

The code with output is:

Again, in the second question, we have to ask user to input numbers, and add them, until a zero is pressed. This is checked by a sentinel value in the while condition.

The code and its output is:

In the third question, we have to use a do while loop to input "hello" 25 times. The code and output is:

In the fourth question, we have do the same as third question, but with a for loop


Related Solutions

Update the function playScratchOffs to do the following Declare an integer variable to store the type...
Update the function playScratchOffs to do the following Declare an integer variable to store the type of scratch off (i.e. type) Declare an integer variable to store the number of scratch off (i.e. count) Declare an integer variable for loop control (i.e. c) Declare a variable of data type struct OneDollar (i.e. oneSO) Declare a variable of data type struct TwoDollar (i.e. twoSO) Declare a variable of data type struct FiveDollar (i.e. fiveSO) Write a series of printf statements to...
The variable smokes is a binary variable equal to one if a person smokes and zero...
The variable smokes is a binary variable equal to one if a person smokes and zero otherwise. Cigprice is the price of cigarettes, white is a dummy variable that takes the value 1 if the person is white and 0 otherwise and restaurn is a dummy that takes the value 1 if the person lives in a state with restaurant smoking restrictions. The estimated linear probability model is smokes = .656 - .069 log(cigpric) + .012 log(income) - .029 educ...
Sum of the deviations from Mean is equal to zero. Check the validity of this statement by taking observations 8. 1 and 6?
Sum of the deviations from Mean is equal to zero.  Check the validity of this statement by taking observations 8. 1 and 6?
1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student...
1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student (as whole number) b. a variable to store a letter grade for a course, like A, B, or C c. a variable to store an average for a student (may have decimal places) d. a variable to represent if a student passed the course or not, with a value of TRUE or FALSE e. a constant to represent the passing grade of 65 2....
Why economic growth is not zero-sum?
Why economic growth is not zero-sum?
Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
*I NEED ALL OF THE QUESTIONS ANSWERED* 1.Heat is (a) equal to temperature, (b) the temperature...
*I NEED ALL OF THE QUESTIONS ANSWERED* 1.Heat is (a) equal to temperature, (b) the temperature change divided by the mass, (c) the mass divided by specific heat, (d) the flow of energy due to a temperature difference. 2.The human temperature sense is associated with (a) sight, (b) smell, (c) touch, (d) hearing. 3.Temperature is a relative measure of (a) transferred energy, (b) hotness or coldness,                     (c) internal energy, (d) specific heat. 4.The temperature difference between the ice and steam...
What does it mean to declare a variable? Give an example.
C++ programming homeworkWhat does it mean to declare a variable? Give an example.What does it mean to assign a value to a variable? Give an example.What is the different between assigning and initializing? Give examples.
Which of the following statements is NOT correct? A. It is allowed to declare a variable...
Which of the following statements is NOT correct? A. It is allowed to declare a variable and initialize it in one statement. B. Once a variable is declared and initialized, you can change its value later on. C. The variable declaration tells the compiler to allocate appropriate memory space for the variable based on its data type. D. It is allowed to declare two variables with the same name but with different data type.
How does one declare a class variable in C#?
How does one declare a class variable in C#?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT