You are on page 1of 2

CEC 101: Computer Programming

Civil Engineering Autumn 2023-24


Prac�cal 4: Condi�onal Statement and loops

Q.1. Write a program to generate the following output:

a)

*******
******
*****
****
***
**
*

b)

1
24
369
4 8 12 16
5 10 15 20 25
...up to N rows, where N should be provided by the user.

c)
X
XX
XXX
XXXX
XXXXX
Q.2. Write a program that asks the user to input a number and prints its factorial.
Q.3. Write a program that prints all the possible coordinates for two rooks that
can be placed on an 8*8 chessboard, so they do not atack each other.

Q.4. Write a program that counts the number of ways two knights can be placed
on an 8*8 chessboard, so that they do not atack each other.
Repeat with dimension (n) of the board (n*n) taken as input from the user.
Q.5. Write a program that takes an input integer between 1 and 7 from the user.
The program should then use a switch-case statement to determine the
corresponding day of the week and print it out. For example, if the user enters 1,
the program should output 'Monday.' If the user enters 5, the output should be
'Friday.' Make sure to handle cases where the user enters an invalid number (less
than 1 or greater than 7) by providing an appropriate error message.

Q.6. Write a program that takes a posi�ve integer 'n' as input from the user. The
program should then generate and print the mul�plica�on table for the given
number in a proper format. The table should include products from 1 to 10.

You might also like