You are on page 1of 2

National University of Sciences & Technology Fundamentals of Computer Programming Course Instructor: Ms Samin Khaliq

Lab 6: Programming Exercises


Exercise 1 (do-while loop Loop always executes at least once) Write a program that calculates and prints the sum of the even integers from 2 to user_defined_limit and product of odd integers from 1 to user_defined_limit. Use a do-while loop that asks the user whether the program should be terminated or not. Also maintain a count as to how many times the user ran the do-while loop.

Exercise 2 (switch statement Multiple selection statement) Write a program that takes two numbers as input from the user. The program should then display a list of arithmetic operations which the user can choose from. The user should be able to select one of the operations (use a switch statement). The program should then evaluate the result corresponding to the users selection. Interaction with the program might look like this:

Exercise 3 (continue statement) Write a program that prints all the numbers from 0 to 29 that are not divisible by 6. Use a continue statement to implement your program.

National University of Sciences & Technology Fundamentals of Computer Programming Course Instructor: Ms Samin Khaliq Exercise 4 (break statement) Type the following code in the editor and examine what the following program does?

You might also like