Skip to content

Latest commit

 

History

History
60 lines (47 loc) · 900 Bytes

File metadata and controls

60 lines (47 loc) · 900 Bytes

NPTEL-Programming-Assignment-T1-Q2

NPTEL Programming Assignment: T1-Q2

T1-Q2

For a number N, you have to do the following operations until you get to 1: if N is even, reduce the number to N/2 and If N is odd, then increase the number to (3*N)+1, and repeat the process till you get 1.

You have to output the number of odd numbers in the sequence of numbers you get in the above algorithm, including the number N (if N is odd) and the number 1.

Sample input 1

3

Sample output 1

3

Explanation of Sample Output 1

The sequence of numbers starting from 3 is 3, 10, 5, 16, 8, 4, 2, 1. In this sequence, 3, 5 and 1 are odd.

Sample input 2

11

Sample output 2

5

Sample input 3

5

Sample output 3

2

Sample input 4

1024

Sample output 4

1

Sample input 5

7

Sample output 5

6