English

Submitted by: Submitted by

Views: 10

Words: 736

Pages: 3

Category: Business and Industry

Date Submitted: 11/05/2015 04:55 AM

Report This Essay

COMSATS Institute of Information Technology Abbottabad

Department of Computer Science

Assignment -III

Introduction to Computers and Programming (BSE 1B) 20 Marks

Due Date: 6/11/2015

Q1. Write a program that prompts the user to input an integer and then outputs both the individual digits

of the number and the sum of the digits. For example, it should output the individual digits of 3456 as 3 4

5 6, output the individual digits of 8030 as 8 0 3 0, output the individual digits of 2345526 as 2 3 4 5 5 2

6, output the individual digits of 4000 as 4 0 0 0, and output the individual digits of -2345 as 2 3 4 5.

Q2.

Q3. Write a program that prompts the user to input a positive integer. It should then output a message

indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd

integer is prime if it is not divisible by any odd integer less than or equal to the square root of the

number.)

Q4. Write a program that uses while loops and for loops to perform the following steps:

a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than

secondNum).

b. Output all odd numbers between firstNum and secondNum.

c. Output the sum of all even numbers between firstNum and secondNum.

d. Output the numbers and their squares between 1 and 10.

e. Output the sum of the square of the odd numbers between firstNum and secondNum.

Q5. The population of a town A is less than the population of town B. However, the population of town A

is growing faster than the population of town B. Write a program that prompts the user to enter the

population and growth rate of each town. The program outputs after how many years the population of

town A will be greater than or equal to the population of town B and the populations of both the towns at

that time. (A sample input is: Population of town A 5000, growth rate of town A 4%, population of town

B 8000, and growth rate of town B 2%)

Q6. Write a program that input for students’ final...