Answer: articles, books, reports, statistics, etc. Library databases may include records of articles, books, dissertations, conference proceedings, videos, sound recordings, reports, statistics, images, and more. Some databases are organized for specific subjects, such as PubMed for health/medicine or Psyc INFO for psychology.
Explanation:
Answer:
- #include <iostream>
- using namespace std;
- int hailstoneLength(int n){
- int term = 1;
- while(n != 1){
- if(n % 2 == 0){
- n = n / 2;
- term++;
- }
- else{
- n = n * 3 + 1;
- term++;
- }
- }
- return term;
- }
- int main()
- {
- cout<<hailstoneLength(8);
- return 0;
- }
Explanation:
Hailstone sequence is a list of number that is generated by following the rules as below:
- Given a starting number (e.g. 5)
- If the number is even, divide it by 2
- If the number is odd, multiply it by 3 and then add 1
- the starting number will either be repeatedly divided or multiplied until the final n reaches 1
So, we can create a function called hailstoneLength that takes one input number, n, as starting number (Line 4).
In the function initialize the variable term with value of 1 (Line 5). Create a while loop and set the condition to enable the loop running until the n become 1 (Line 6). In the loop, keep checking the n value if it is currently even or odd using modulus operator (Line 7 - 14). If it is even, divide n by 2 and increment the term by one (Line 7 - 10). If it is odd, multiple it by 3 and add 1 (Line 11 - 14). At last, return term value as output (Line 16).
In the main program, test the function by passing 8 as argument. We shall get the output of 4 (Line 21).