CSE 103: Computer Programming in C Lab #5: Repetition Structures - Part II Obiective Learn the Repetition Structures by covering the following loops: 1. Do-while statement 2. Nested loops Task 1A do-while statement Write Compile & Run the following program in Dev-C++, Save the source file in a new folder Lab6 as Lab/programi.c r* computing the area and circumference of any circle #include
#define PI 3.142857 int main(void double radius, area, cir; char ans do 1 area printf(" Enter a value for radius:"); scanf("11", Gradius); PI. radius. radius cir - 2.PI radius; printf("The area of a circle with radius 1.218- 8.21: ". radius, area): printf("and the circumference - 1.212 ", cin); print(" Do you wish to try again ly)? "); scanf("%c", sans); while (ans - Yt 11 ans - '); printf(" Good bye!! "); return 0; 1. Draw the flowchart of the program Page 1 of 1 Read 7777 ????????? Print 2727 Readres FALSE res s'Y'? TRUE Print "Good bye" Page 2 of 11 3. Give a sample Output of the program 4. Run the Debugger on the program several times and write down your observations regarding do-while statement Observations: 3. Rewrite Program).c using while loop. Save the source file in a new folder Lab6 as Lab6/program2.c Note: Program2.c must have the same behaviour (semantee) of Programl.c, ie, the loop body must be executed at least once! * Programi using while-loop / #include #define P1 3.142857 int main(void) { double radius, area, cir; char ans; printf(" Good bye!! "); return 0; Conclusion: We can tese while for do-while statements interchangeably provided that we make the necessary changes to our program! Page 4 of 11 Task 2: Nested for loops: Write Compile & Run the following program in Dev-C++. Save the source file in as Lab6/program3.c Compile & Run the C program in Dev-C++. Finclude int main(void) int i, j, rows, columns; rows 10 columns - 10 for(i=1;i int main(void) { int i, j, rows. columns; rows = ?? columns = ??? return 0; Page 6 of 11 Task 3. Nested for loops Write Compile & Run the following program in Dev-C++, Save the source file in as Lab6/programs.c Compile & Run the program in Dev-C++. Vinclude int main(void) int 1,3 forti - 11 int main(void) { int i, j, TONS, columns; return 0; Page 7 of 11 3. Modify Programo to get the following output Save the source file in as Lab6/program7.c 12 x 21 123 x 321 1234 X 4321 12345 X 54321 123456 X 654321 1234567 X 7654321 12345678 X 87654321 123456789 X 987654321 /* Program7: Modified version of Program / Winclude int main(void) Int 1.3, rows, columns; return 0; 4. Modify Program to print Pascal Triangle as shown below: Save the source file in as Lab6/program8.c 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321 12345678987654321 /Programe : Modified version of program to print Pascal Triangle / Vinclude int main(void) int 1, 3, rows, columns; return 0; Page 8 of 11