Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Overview The following exercise gives you a number of looping exercises such as getting the same behavior using different loops. There are also patterns

image text in transcribedProgram Overview The following exercise gives you a number of looping exercises such as getting the same behavior using different loops. There are also patterns to replicate using code, e.g., a right-triangle. The triangle must be produced using as few lines of code as possible. This introduces the need for utilizing loops and coming up with the most efficient way to implement loops nested within each other to produce the desired effect. The point of the exercise then is to observe patterns in detail and be able to devise conditions and logic to produce the pattern. The patterns are not an end in themselves instead they give us the opportunity to gain expertise with logic and interpreting nested loops.

1) Do loop. Write the code to calculate the average of series of numbers that the user enters using a do loop (also generically called a do-while loop). Prompt the user to enter as many numbers as he or she likes, i.e. you do not know in advance how many repetitions you need. Maintain a running total of all numbers using the accumulated total structure. Stop asking for more numbers when the user enters x. Calculate the average of all the numbers entered and print it to the Console. You will need to evaluate if the user entered x or not before you can convert it to an integer (the program will crash if you try converting an x into an integer). So, do not call ReadLine and Convert in the same line and instead break that process down into two lines. Read input first, then using an if statement decide if you want to convert it into a number or if you should instead exit the loop using the break statement.

2) Implement Part (1) using a while loop. Implement identical behavior using the same variables. Those variables will have other previous values in them from part (1), i.e. what we would call garbage (e.g., the values inside the total variable, might be good elsewhere, but theyre not valid now in this situation. Therefore the values are garbage to be thrown out.) Before you reuse any variables, you must always therefore reset or reinitialize them. This means, assign the variables the same values you assigned them at declaration, i.e. set integers to zero again, etc. However, do not declare the variables again. Reuse the existing variables, do not create new ones (typing in the data type means you are trying to declare variables).

3. Create the following triangle pattern using nested for loops. Your code should not have more than 2 Write/WriteLine statements the entire pattern should be created using the logic of nested loops.

4) Create the following triangle pattern using nested for loops.

5) Create an equilateral triangle of 5 levels. Place your triangle towards the center of the screen by inserting extra spaces. In the sample, the top row has 20 spaces preceding the first star.

Use the C# to do this project ,project should like the image

5184277-dt-content-rid-106389679 1/courses/2017Fall-T-CIS340-85825 5.pdf ctS34IC5.pdf Class: Lage and Looping Exereises he werae o all nder i 67.25 Teno ueiny hile loop tu zce that the ucruge preduced usin while and do iz identical FleG ACIS 340 Spring 2017 Altaf Ahmed and Arion Board of Regents

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

How can you defend against SQL injection attacks?

Answered: 1 week ago