Practice Set 2
1. Write a program to print the following pattern. Take a number of lines as input. For
example, for input 5 the output is shown below:
1
11
111
1111
11111
2. Write a program to print the factorial of a number which is taken as input. Remember, the
input can be anything between 1-100.
3. Given a number, check whether it is a strong number or not. A strong number is a
special number, such that the sum of the factorials of all digits present in the number
should be equal to the number itself.
4. Write a program to check whether a 3-digit number follows the given property or not. If
the number follows it, print “Yes”, otherwise print “No”.
Property: the sum of cubes of each digit is less than the number
Example: 111 follows the given property as (1*1*1 + 1*1*1 + 1*1*1) < 111
5. 11. Check if the input phone number p is valid or not. A phone number is valid if,
a. It contains 10 digits
b. It may contain 11 digits, but in that case the first digit should be 0
c. The starting digit should be either 9, 8 or 7
Take p as input and output 1 if the phone number is valid else output 0.
6. Write a C program to check if a given number is an Armstrong number.
Example: 153 → 1³ + 5³ + 3³ = 153
7. Write a C program to print all twin prime pairs between 1 and 100.
Twin primes are pairs of prime numbers that differ by 2.
Example: (3,5), (5,7), (11,13), (17,19)...
8. Write a C program that repeatedly displays a menu and performs the selected operation
using a switch statement.
Menu:
1. Find GCD of two numbers
2. Find LCM of two numbers
3. Check if a number is Prime
4. Exit
9.Write a C program to print the following pattern for a given number of rows n.
Example: For n = 5, the output should be:
10.Write a C program to print the following pattern for a given number of rows n.
Example: For n = 5, the output should be:
*****
****
***
**
**
***
****
*****