Codelab excercise 2- computer programming

Click For Summary
SUMMARY

The forum discussion centers on a programming homework assignment involving integer manipulation and control structures in a programming language. Key tasks include using auto-increment and auto-decrement operators, while loops, do...while loops, and for loops to perform operations such as printing asterisks and calculating sums of squares and cubes. The instructor emphasizes the importance of initializing variables and making an effort before seeking help, highlighting the educational value of problem-solving.

PREREQUISITES
  • Understanding of integer variables and their manipulation
  • Familiarity with control structures: while loops, do...while loops, and for loops
  • Knowledge of auto-increment and auto-decrement operators
  • Basic programming logic and problem-solving skills
NEXT STEPS
  • Practice using auto-increment and auto-decrement operators in various scenarios
  • Learn how to implement while loops for different output patterns
  • Explore the differences between do...while loops and while loops
  • Study how to use for loops for iterative calculations and output
USEFUL FOR

Students learning programming concepts, educators teaching control structures, and anyone looking to improve their coding skills in integer manipulation and loop constructs.

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
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 16 ·
Replies
16
Views
12K
  • · 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