Program 4.1 Input: Laboratory 5
Program 4.1 Input: Laboratory 5
1 Input
Output
Output
Output
Output
Output
Output
Output
Output
Output
Output
Change the program to make outside loop 6times and inside loop 3 times Input
Output
Exercise 1 1. Write a program to calculate sum of number and multiple of number. Example output: Sum of number 1 to 7 = 28 Multiply of number 1 to 7 = 5040
Input
Output
Exercise 2 1. Write a program asking user to insert how many number they want to display symbol $. Example: How many tome to display symbol,,$?: 7 $$$$$$$
Input
Output
Exercise 3
Input
Output
Questions 2. What is the function of ,,for statement. For: For statement are also called entry controlled or close ended because the condition for iteration of loop is check at the string of the loop and loop will not execute even once if the condition will to satisfy even once. 3. Write a discussion in every program above. Program 4.2 -We can learn the function of dowhile. This is a program for loop control structure. This program will automatically loop without need to input anything. It can loop anything such as number. If we want to calculate the sum of number 1 to number 10, we can use this statement to calculate it. We must use additional operation in order to calculate the sum of number 1 to number 7. The output of this program should be: The sum of 1 to 10 is 55. Program 4.3 -This program using for statement. For and dowhile statement has the same function which is loop control structure. But for statement is more simple than dowhile and very easy to use. The output of this program is 1,2,3,4,5,6,7,8,9 because we choose to display digit 1 to 9. Program 4.4 - This program also using for statement but is has two times of loop control structure. There are two variables in this program which is in_loop and out_loop. In_loop control the number of output in a row and out_loop control the number of row. 4. Compare the differences between the various loop structure.
In this lab, we use three types of loop control structure which is while, dowhile and for. All of these statement has a same function but different format and for statement is the easiest to use. For an example: for(digit=0;digit<=9;++digit) do { total +=n; n++; } while (n<=limit);
Conclusion After do this LAB 5 (Repetition Structure) we know how to writing C program using looping statements. Loops are used to repeat a block of code. Being able to have your program repeatedly execute a block of code is one of the most basic but useful tasks in programming -- many programs or websites that produce extremely complex output (such as a message board) are really only executing a single task many times. (They may be executing a small number of tasks, but in principle, to produce a list of messages only requires repeating the operation of reading in some data and displaying it.) Now, think about what this means: a loop lets you write a very simple statement to produce a significantly greater result simply by repetition.
Next, we know how to describe the different type of looping structures: For While, dowhile Nested looping We also know how to compare the difference between the various loop structures.