0% found this document useful (0 votes)
25 views

Lab 6: Programming Exercises: Fundamentals of Computer Programming

The document contains instructions for 4 programming exercises from a Fundamentals of Computer Programming course at National University of Sciences & Technology. Exercise 1 involves writing a do-while loop to calculate sums and products of even and odd integers based on a user-defined limit. Exercise 2 involves using a switch statement to allow a user to select an arithmetic operation and calculate the result of two input numbers. Exercise 3 prints numbers from 0 to 29 not divisible by 6 using a continue statement. Exercise 4 examines the use of a break statement in a provided code sample.

Uploaded by

Fakhar Abbas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Lab 6: Programming Exercises: Fundamentals of Computer Programming

The document contains instructions for 4 programming exercises from a Fundamentals of Computer Programming course at National University of Sciences & Technology. Exercise 1 involves writing a do-while loop to calculate sums and products of even and odd integers based on a user-defined limit. Exercise 2 involves using a switch statement to allow a user to select an arithmetic operation and calculate the result of two input numbers. Exercise 3 prints numbers from 0 to 29 not divisible by 6 using a continue statement. Exercise 4 examines the use of a break statement in a provided code sample.

Uploaded by

Fakhar Abbas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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