Assign 03
Assign 03
Assign 03
A. While loop
1. Write a program to accept a character and a number, and print the character number times
Input:
Character: *
Number: 6
Output:
******
d. Check whether it is Armstrong no. (when sum of cube of all digits of equals the number
then the number is called as Armstrong number)
Example: 153
(1 * 1 * 1)+(5 * 5 * 5)+(3 * 3 * 3) = 1 + 125 + 27 = 153
Input: 936
Output: 936 is not an Armstrong number
Input: 153
Output: 153 is an Armstrong number
6. Write a program to accept a number and print all factors excluding the number
Input: 24
Output: all factors: 1, 2, 3, 4, 6, 8, 12
7. Write a program to accept a number and print unique pairs of numbers such that multiplication of
the pair is given number
Input: 24
Output:
1 * 24 = 24
2 * 12 = 24
3 * 8 = 24
4 * 6 = 24
9. Write a program to accept two numbers and find its GCD (greatest common divisor) using
Euclidean algorithm. The following example explains the algorithm. GCD of 123 and 36 is 3
123 % 36 = 15
36 % 15 = 6
15 % 6 = 3
6 % 3 = 0
GCD = 3
Input:
no1: 123
no2:36
Output:
123 % 36 = 15
36 % 15 = 6
15 % 6 = 3
GCD of 123 and 36 is 3
B. For loop
12. Write a program to accept integer values of base and index and calculate power of base to
index.
Input: base: 2 index: 5
Output: 32
Input: base: 8 index: 3
Output: 512
C. Do while loop
15. Modify the menu driven program for four function calculator. Add a menu item to choose
option exit. The program continues till user chooses option exit.
16. Write a program to develop a very simple version of the ''guess the magic number" game. The
program generates a random magic number between 1 and 1000. Ask user to guess the
number. If guess is correct then print message congrats! You won. if the guess is less than
magic number print the message ** left ** otherwise print the message ** right **. Repeat the
procedure till player give accurate guess. Give maximum 10 chances to user.
Note: generates the magic number using the standard random number generator rand( ), which
returns an arbitrary number between 0 and RAND_MAX (which defines an integer value that
is 32,767 or larger). The rand( ) function requires the header <stdlib.h>.
18. Write a program to print the tables of the numbers from 1 to 10.
19. Modify above program (18) to accept a range i.e. two numbers and print tables of numbers
within the range.
Input: 3 6
Output:
3 4 5 6
6 8 10 12
9 12 15 18
12 16 20 24
15 20 25 30
18 24 30 36
21 28 35 41
24 32 40 48
27 36 45 54
30 40 50 60
21. Write a program to display First 5 prime numbers after a given number.
Input: 7
Output: 11 13 17 19 23
22. Print following patterns
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
1 5
1 2 5 4
1 2 3 5 4 3
1 2 3 4 5 4 3 2
1 2 3 4 5 5 4 3 2 1
G
E F G F E
C D E F G F E D C
A B C D E F G F E D C B A
C D E F G F E D C
E F G F E
G
A A B C D
B C B C D
D E F C D
G H I J D