C++ Programming/Exercises/Iterations/Pages

Solutions requirements Solutions must: and should: Please do not add solutions that are 99% similar to another that is already present, if it is an improvement just add it to the existing solution.
 * Use only standard C++.
 * Be compilable.
 * Be in accordance to general coding practices. (no esoteric demonstrations are required)
 * Handle error situations, even if behavior is not defined. Acceptable default is simply reporting an "Error".
 * Be internally consistent in relation to the adopted coding-style.
 * Be as simple as possible on to the point (use the minimum required variables and function calls/classes and reduces convoluted I/O handling).

Exercise 1
Write a program that asks the user to type an integer and writes "YOU WIN" if the value is between 56 and 78 (both included). In the other case it writes "YOU LOSE".

Exercise 2
Write a program that asks the user to type all the integers between 8 and 23 (both included) using a for loop.

Exercise 3
Same as Exercise 2 but you must use a while.

Exercise 4
Write a program that asks the user to type 10 integers and writes the sum of these integers.

Author: jimmymass;

Exercise 5
Write a program that asks the user to type 10 integers and writes the smallest value.

Exercise 6
Write a program that asks the user to type an integer N and computes the sum of the cubes from 53 to N3.

Exercise 7
Write a program that asks the user to type an integer N and compute u(N) defined with : u(0)=3 u(n+1)=3*u(n)+4

Exercise 8
Write a program that asks the user to type an integer N and compute u(N) defined with : u(0)=1 u(1)=1 u(n+1)=u(n)+u(n-1)

Exercise 9
Write a program that asks the user to type an integer between 0 and 20 (both included) and writes N+17. If someone types a wrong value, the program writes ERROR and he must type another value.

Exercise 10
Write a program that is able to compute some operations on an integer. The program writes the value of the integer and writes the following menu :

1. Add 1 2. Multiply by 2 3. Subtract 4

4. Quit

The programs ask the user to type a value between 1 and 4. If the user types a value from 1 to 3 the operation is computed, the integer is written and the menu is displayed again. If the user types 4, the program quits.

Exercise 11
Write a program that asks the user to type a positive integer. When the user types a negative value the program writes ERROR and asks for another value. When the user types 0, that means that the last value has been typed and the program must write the average of the positive integers. If the number of typed values is zero the program writes 'NO AVERAGE'.

Exercise 12
Write a program that asks the user to type an integer N and compute u(N) defined with : u(0)=3 u(1)=2 u(n)=n*u(n-1)+(n+1)*u(n-2)+n

Exercise 13
Write a program that asks the user to type 10 integers and write the number of occurrence of the biggest value.

Exercise 14
Write a program that asks the user to type the value of N and computes N!.

Exercise 15
Write a program that asks the user to type an integer N and that indicates if N is a prime number or not.

Exercise 16
Write a program that asks the user to type an integer N and that writes the number of prime numbers lesser or equal to N.

Exercise 17
Write a program that asks the user to type the value of an integer N and compute the N-st prime number.

Exercise 18
Write a program that asks the user to type the value of N and writes this picture :

and so on...

Exercise 19
Write a program that asks the user to type the value of N and display an output like the following:

and so on ...

Exercise 20
u(n) is defined with:


 * u(0) = a (a is an integer)
 * if u(n) is even then u(n+1)=u(n)/2, else u(n+1)=3*u(n)+1

Conjecture: For all value of a, there exists a value N such that u(N)=1.

a)Write a program that asks the user to type the value of an integer a and writes all the values of u(n) from n=1 to n=N.

b) Write a program that asks the user to type a value M and computes the value of a from 2 and M that maximizes the value of N. This value is called A. The program must write the value of A and N.

Exercise 21
Request the user to type numbers, each time printing its triple, until the user enters -999.

Exercise 22
Request the user to type positive numbers until either a zero or a negative is typed, and then show the user how many positives were typed in.

Exercise 23
Request the user to type positive numbers, or to stop by typing a number smaller than 1. Print the average.

Exercise 24
Request the user to type numbers, or type 0 to stop. Show how many numbers were between 100 and 200 (both included).

Exercise 25
The country A has 50M inhabitants, and its population grows 3% per year. The country B, 70M and grows 2% per year. Tell in how many years A will surpass B.

Exercise 26
Write a program that asks the user to input 5 sequences of characters. Then it will ask the user for a character to search for and will output the maximum number of times that it occurred between the 5 sequences. Example: Sequence 1: aabc Sequence 2: aaaa If the user chooses to search for character 'a', the program will output "Character a occurred a maximum of 4 times" because it occurred 4 times in the second sequence, and only twice in the first sequence.

Exercise 27
Write a program that asks the user to type a random number. Write in the output if this number is a prime number or not. Write which numbers your number can be divided by.

Exercise 28
Write a program for finding the amount of a specific character inside a string.

Exercise 29
Write a Program to find out no. of Even & Odd no. in a given Data Series.

Exercise 30
Write a Program to count Zero, Positive, Negative no. in a given Data Series.

Exercise 31
Write a program to count the numbers which are divisible by 3 in a given Data Series.