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

Assignment 3C: Answer the following questions Question 1. a. Declare a 32-bit signed integer variable and...
Assignment 3C: Answer the following questions Question 1. a. Declare a 32-bit signed integer variable and initialize it with the smallest possible negative decimal value. b. Declare an uninitialized array of 100 16-bit unsigned integers. c. Declare a string variable containing the word “DVC” repeated 20 times, and terminated with the null char. Question 2 For the following declarations, assuming that the address of I is 404000h What are the addresses of J, K, and L? What is the total...
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...
SOLVE USING WHILE. A perfect number is a positive integer that is equal to the sum...
SOLVE USING WHILE. A perfect number is a positive integer that is equal to the sum of its positive divisors except the number itself. The first two perfect numbers are 6 and 28 since 1+2+3=6 and 1+2+ 4+7+14=28. Write a matlab computer program that finds the first n perfect number (the user must input the value of n) and show them in a vector thanks! xo
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an integer pointer p. 3. Let p pointing to the array a[ ]. 4. Use p (you have to use p) to put 0 into the first element of this array, 2 into the second element, 4 into the 3rd element, 6 into the 4th element, ... 198 into the 100th element of this array. 5. Use a (you have to use a) to display...
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...
I have a python program that must check if an integer is the sum of the...
I have a python program that must check if an integer is the sum of the squares of four consecutive prime numbers. However, when I run the program, it goes into an infinite while loop, and it doesn't give me any answer. I can only use the while, if, else, True and False commands. The code I'm using is n1=2   n2=3   n3=5   n4=7   n = int(input("n: "))   if (n==(n1**2)+(n2**2)+(n3**2)+(n4**2)):     print(n1,n2,n3,n4)   else :     i = 2     pr = True     next =...
Java language (a) Write code segments to perform the following: (i) declare and create an integer...
Java language (a) Write code segments to perform the following: (i) declare and create an integer array freqArray of size 8 (ii) declare and initialize an array weight (with suitable type) which contains 48.5, 80 and 68 (iii) declare a Mouse array of size 2 with name mouse and initialize it with Mouse objects using one statement (b) A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3};...
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....
A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String...
A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String variable called myString1 and initialize it to "Programming". C) Declare a String variable called myString2 and initialize it to "Language". D) Print the concatenation of myString0 + " is a " + myString1 + " " + myString2 + ".". E) Print the sum of the lengths of myString1 and myString2 (must call the length() method). F) Print the 2nd, 4th, and 7th character...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT