Codelab excercise 2- computer programming

Click For Summary
The discussion revolves around a programming homework assignment that includes various tasks involving auto-increment and auto-decrement operators, while loops, do...while loops, and for loops. Participants are encouraged to attempt the problems independently before seeking help, emphasizing the importance of demonstrating effort. Specific tasks include printing asterisks, calculating sums of squares and cubes, and using control structures effectively. The instructor notes that variables must be initialized before use in loops. Overall, the focus is on practicing programming logic and control structures in a structured manner.
goku3240
Messages
4
Reaction score
0

Homework Statement



1) Given an integer variable strawsOnCamel , write a statement that uses the auto-increment operator to increase the value of that variable by 1.

2) Given an integer variable timer , write a statement that uses the auto-decrement operator to decrease the value of that variable by 1.

3) Given an int variable k that has already been declared, use a while loop to print a single line consisting of 97 asterisks. Use no variables other than k .
4) Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .
5)
Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total . Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total . Use no variables other than k and total .


Instructor's notes: You must initialize the value of the variables total and k prior to your loop.
6) Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a while loop to compute the sum of the cubes of the first n counting numbers, and store this value in total . Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total . Use no variables other than n , k , and total . Do NOT modify n .

7) Given an int variable k that has already been declared, use a do...while loop to print a single line consisting of 97 asterisks. Use no variables other than k .
8) Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .
9) Given int variables k and total that have already been declared, use a do...while loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total . Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total . Use no variables other than k and total .

10)Given an int variable k that has already been declared, use a for loop to print a single line consisting of 97 asterisks. Use no variables other than k .
11)Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a for loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .
12)
Given int variables k and total that have already been declared, use a for loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total . Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total . Use no variables other than k and total . Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0.
14)Assume that the int variables i , j and n have been declared, and n has been initialized. Write code that causes a "triangle" of asterisks to be output to the screen, i.e., n lines should be printed out, the first consisting of a single asterisk, the second consisting of two asterisks, the third consisting of three, etc. The last line should consist of n asterisks. Thus, for example, if n has value 3, the output of your code should be (scroll down if necessary):
*
**
***






Homework Equations



use repitation if else control structures

The Attempt at a Solution



got like 5 of em rest have weird logic
 
Physics news on Phys.org
Per the forum rules here, you need to make an effort at this yourself before getting help.
On helping with questions: Any and all assistance given to homework assignments or textbook style exercises should be given only after the questioner has shown some effort in solving the problem. If no attempt is made then the questioner should be asked to provide one before any assistance is given. Under no circumstances should complete solutions be provided to a questioner, whether or not an attempt has been made.​
 

Similar threads

  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 3 ·
Replies
3
Views
10K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 16 ·
Replies
16
Views
11K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K