Starting Vocational Training From 1-May-2024 Get Detail

1.

Solution

Write a program in C++ to display the first n terms of 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

Solution

2.

Solution

Write a program in C++ to display the cube of the number upto given an integer.

Sample Output:

Input the number of terms : 5

Number is : 1 and the cube of 1 is: 1

Number is : 2 and the cube of 2 is: 8

Number is : 3 and the cube of 3 is: 27

Number is : 4 and the cube of 4 is: 64

Number is : 5 and the cube of 5 is: 125

Solution

3.

Solution

Write a program in C++ to list non-prime numbers from 1 to an upperbound.

Sample Output:

Input the upperlimit: 25

The non-prime numbers are:

4 6 8 9 10 12 14 15 16 18 20 21 22 24 25

Solution

4.

Solution

Write a program in C++ to calculate the series (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n).

Sample Output:

Input the value for nth term: 5

1 = 1

1+2 = 3

1+2+3 = 6

1+2+3+4 = 10

1+2+3+4+5 = 15

The sum of the above series is: 35

Solution

5.

Solution

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

Solution

6.

Solution

Write a program in C++ to find the sum of digits of a given number.

Sample Output:

Input a number: 1234

The sum of digits of 1234 is: 10

Solution

7.

Solution

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

Solution

8.

Solution

Write a program in C++ to find prime number within a range.

Input number for starting range: 1

Input number for ending range: 100

The prime numbers between 1 and 100 are:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

The total number of prime numbers between 1 to 100 is: 25

Solution

9.

Solution

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.

Solution

10.

Solution

Write a program in C++ to find the perfect numbers between 1 and 500.

The perfect numbers between 1 to 500 are:

6

28

496

Solution

11.

Solution

Write a program in C++ to display n terms of natural number and their sum.

Sample Output:

Input a number of terms: 7

The natural numbers upto 7th terms are:

1 2 3 4 5 6 7

The sum of the natural numbers is: 28

Solution