0% found this document useful (0 votes)
16 views

For Loop Sheet

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

For Loop Sheet

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Sheet

1. Write a program in C++ to find the first 10 natural numbers.


Sample output:
The natural numbers are:
1 2 3 4 5 6 7 8 9 10

2. Write a program in C++ to find the sum of the first 10 natural


numbers.
Sample Output:
Find the first 10 natural numbers:
---------------------------------------
The natural numbers are:
1 2 3 4 5 6 7 8 9 10
The sum of first 10 natural numbers: 55

3. Write a program in C++ to check whether a number is prime or not.


Sample Output:
Input a number to check prime or not: 13
The entered number is a prime number.

4. Write a program in C++ to find the factorial of a number.


Sample output:
Input a number to find the factorial: 5
The factorial of the given number is: 120

5. Write a program in C++ to find the sum of the series 1 + 1/2^2 +


1/3^3 + ..+ 1/n^n.
Sample Output:
Input the value for nth term: 5
1/1^1 = 1
1/2^2 = 0.25
1/3^3 = 0.037037
1/4^4 = 0.00390625
1/5^5 = 0.00032
The sum of the above series is: 1.29126

6. Write a program in C++ to find the number and sum of all integers
between 100 and 200 which are divisible by 9 .
Sample Output:
Numbers between 100 and 200, divisible by 9 :
108 117 126 135 144 153 162 171 180 189 198
The sum : 1683

7. Write a program in C++ to display the numbers in reverse order.


Sample Output:
Input a number: 12345
The number in reverse order is : 54321

8. Write a program in C++ to find the Greatest Common Divisor (GCD)


of two numbers.
Sample Output:
Input the first number: 25
Input the second number: 15
The Greatest Common Divisor is: 5

9. Write a C++ program that asks the user to enter positive integers in
order to process count, maximum, minimum, and average or terminate
the process with -1.
Sample Output:
Your input is for termination. Here is the result below:
Number of positive integers is: 4
The maximum value is: 9
The minimum value is: 3
The average is 6.00

10. Write a program in C++ to display the first n terms of the Fibonacci
series.
Sample Output:
Input number of terms to display: 10
Here is the Fibonacci series upto to 10 terms:
0 1 1 2 3 5 8 13 21 34

You might also like