0% found this document useful (0 votes)
50 views1 page

Assignment 3

Uploaded by

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

Assignment 3

Uploaded by

Ar Yan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Assignment 3

Introduction to Computer Programming


BPH-2
Note: Any/all material found copied will be marked zero and the assignments discarded. Both
the original and copied assignments will be treated equally.

Write a C++ program that takes a number N as input, and prints a sequence of
numbers. The first term in this sequence should be N. The second term should be
calculated using the following scheme:
 If term is even, the next term is N/2
 If term is odd, the next term is 3N+1

The third term is calculated from the second term using the same scheme; the
fourth term is calculated from the third term using the same scheme, and so on.
You should stop when the last term you have printed is 1. Your code should also
print the total number of terms in the sequence.

Sample Output:
Enter a number: 6
Series: 6 3 10 5 16 8 4 2 1
Total terms: 9

Enter a number: 22
Series: 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
Total terms: 16
Submission Deadline: Submit your assignments on portal till 16th Nov, 2019.

You might also like