Question: Please help writing the following : preferably use notepad++ windows 7 Mathematical Background (the 3n + 1 Problem) In 1937, German mathematician Lothar Collatz made
Please help writing the following : preferably use notepad++ windows 7
Mathematical Background (the 3n + 1 Problem)
In 1937, German mathematician Lothar Collatz made the following claim:
Take any number n. If it is even, divide it by two. If it is odd, multiply it by three and add one.
Repeat this procedure with the result. No matter what value of n you start with, you will
eventually end up with one.
1/22/2018 Lab 2 - Iterative Statements
This became known as the "Collatz conjecture" and, while no counterexample has ever been
found, it has yet to be proven despite years of mathematical research. It remains an unsolved
problem in mathematics.
In this assignment, you will implement code to allow the user to test this conjecture. Use this
page to test your initial values http://www.ericr.nl/wondrous/showsteps.html
IV. Part 1: collatz
In a file collatz.c fill in the following template:
/*
* Programmer:
* Class: CptS 121, Spring 2011
* Programming lab:
* Date:
* Description:
*/
#include
int main(void)
{
/*
* The main function should implement these steps:
*
* 1. Prompt the user to enter an integer n.
* 2. Check to make sure the integer is positive. If it isn't, print
* out an error message and exit.
* 3. Implement this pseudocode:
*
* as long as n is not equal to 1,
* print the value of n on a line
* if n is even,
* divide it by 2 and store the result back in n
* otherwise,
* mulitply it by 3, add 1, and store the back in n
* print the value of n on a line (it will be 1)
*/
return 0;
}
Compile the program with:
$ cc -Wall collatz.c -o collatz
Here's an example your compiled program should duplicate:
$ ./collatz
enter n: 3
3
10
5
16
8
4
2
1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
