C Class 5
.. Previous Page
Class recording: Here
February 06th, 2022
[Scroll to the bottom of this page to discuss stuff].
Tasks
do…while loop
- Write a program (WAP) that asks the user to enter an integer. If the number is even, the program should display the square of the number and continue asking the user to enter another number. If the number is odd, the program should display the square root of the number and continue asking the user to enter another number. The program should stop when the user enters 0 or negative number.
break, continue, nested loops
- Write a program that asks user for a number in a loop and then:
- if the number is even (except 2), continues to the next iteration
- else if number is non-prime, print that the number is odd and non-prime.
- else if the number is prime, print that the number is prime and exit the loop.
- WAP to display all palindromic numbers b/w 1 and 500.
- WAP to print the binary representation of all number b/w 1 and 500.
Print series
Write separate programs to print the following series:
- 1, 4, 7, 10, …, 100
- 1, 4, 9, 16, …, 100
- 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …, 100 <- This is called the Fibonacci series.
Print patterns
Write separate programs using nested loops to print the following patterns:
-
-
-
-
#
# #
# # #
# # # #
# # # # #
-
123454321
1234321
12321
121
1
-
1
212
32123
4321234
543212345
-
1 1
12 21
123 321
1234 4321
123454321