Codelab excercise 2- computer programming

In summary: If a questioner is unable to show any effort at solving a problem then assistance should be limited to providing hints.
  • #1
goku3240
4
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
  • #2
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.​
 

Related to Codelab excercise 2- computer programming

What is Codelab Exercise 2 and why is it important?

Codelab Exercise 2 is a computer programming exercise designed to help individuals learn and practice basic programming skills. It is important because programming is a crucial skill in today's digital world and Codelab provides a structured and hands-on approach to learning.

What programming language is used in Codelab Exercise 2?

The programming language used in Codelab Exercise 2 is Python. Python is a popular and versatile programming language that is widely used in various fields such as web development, data analysis, and artificial intelligence.

Do I need any prior programming experience to complete Codelab Exercise 2?

No, prior programming experience is not necessary to complete Codelab Exercise 2. The exercise is designed for beginners and includes step-by-step instructions and explanations to help individuals learn and understand programming concepts.

How long does it take to complete Codelab Exercise 2?

The time it takes to complete Codelab Exercise 2 can vary depending on an individual's prior experience and learning speed. On average, it can take anywhere from 1-2 hours to complete the exercise.

Can I get help if I get stuck on a certain step in Codelab Exercise 2?

Yes, there are various resources available to help individuals who get stuck on a certain step in Codelab Exercise 2. These include online forums, tutorials, and the Codelab support team. It is important to not give up and seek help when needed to fully understand and complete the exercise.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
23
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
923
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
895
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
Back
Top