You are on page 1of 3

Computer Science (C++)

Ass#4 - while, dowhile and for


1. Write a C++ program to find the factorial of a given number and display the following output :
Input: 5
Output: 5! = 5 x 4 x 3 x 2 x 1 = 120
2. Write a C++ program to generate the Fibonacci series from 1 to 100.
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
3. Write a C++ program that will print first 20 numbers of Fibonacci series.
4. Write a C++ program to print the table of any number up to any number.
Sample output:
Enter the value of N: 7
Enter the value of M: 3
7x1= 7
7 x 2 = 14
7 x 3 = 21
Continue (y/n)? :
5. Write a C++ program to accept an integer and reverse the integer, display both the reverse and
original number on screen. e.g. Input : 235 then output : Original No. is 235 , Reverse No. is
532
6. Write a C++ program to accept an integer, calculate and display the sum of its digits.
e.g. If Input is 235, Output: 2 + 3 + 5 = 10
7. Write a program that will read 10 numbers and display the following:
(i)
Maximum of the series.
(ii)
Minimum of the Series.
(iii)
Difference between maximum and minimum of the series.
8. Find the greatest integer whose square is less than 142,619.
9. Write a program in C++ that computes the average of all the legal examination scores. A legal
score is one in the range 0 to 100. Your program should read 10 numbers and compute the
following:
(i)
The average of all legal scores.
(ii)
The number of legal scores.
(iii)
The number of illegal scores.
10. Write a C++ program to print the largest number from the list of numbers entered through the
keyboard. The list should be terminated as soon as the user enters 0.
11. Write a program in C++ that will read an integer, Stop reading the value when you encounter a
value of 0 (zero). Count and display the number of positive and negative integers read.
12. Write a C++ program to print all the perfect number less than 160.
Note: A perfect number is one whose sum of factors excluding the number itself is the same as
the number
e.g. , 6 = 1 + 2 + 3
13. Write a program in C++ that will print prime numbers from 1 to 100.

14. Write a program in C++ that will print prime numbers from 20 to 90.
15. Write a program in C++ that will print first 20 prime numbers.
16. Write a C++ program to print the sum of the following series:
i)
2 + 4+ 6 + 8 + 10 +.up to N terms.
ii)
13 + 33 + 53 + 73 + up to N terms.
iii)
1 + + 1/3 + + 1/5 .up to N terms.
iv)
1/22 + 1/42 + 1/62 + 1/82up to N terms.
17. Write a program in C++ That will compute the sum of the following series:
(1) + (1 + 2) + (1 + 2 + 3) + (1 + 2 + 3 + 4) + .. up to n terms.
18. Write a program in C++ That will compute the sum of the following series:
(22)+ (22+ 42) + (22+ 42 + 62) + (22 + 42 + 62 + 82) + .. up to n terms.
19. The temperature on the Celsius scale are related to those on the Fahrenheit scale by the formula:
C = 5/9*(F-32)
Write a program that prints the Celsius equivalent of Fahrenheit temperatures in the range low to
high where low and high be the input to the program.
20. Write a program in C++ that will print the following :
Note: The Input to your program is number of rows.
(a) * * * * *
(b) * * * * * (c)
*
****
****
***
***
***
*****
**
**
*
*
21. Write a Program in C++ that will print the following:
$
$ $
$ $ $
$ $
$
The Input to your program is the maximum number of $ sign.
22. Write the Program in C++ that will print the following:
*
* * *
* * * * *
* * *
*
The Input to your program is the maximum number of asterisks.

23. Write the Program in C++ that will print the following:
1
12
123
1234
The Input to your program is the number of rows.

24. Write the Program in C++ that will print the following:
A BCD
BCD
CD
D
The Input to your program is up to which alphabetic character (here D).
25. Write the Program in C++ that will print the following:
A
B A
C BA
D CBA
C BA
B A
A
The Input to your program is up to which maximum alphabetic character (here D).

You might also like