+30 C++ Loop Exercise

Congratulations on completing the C++ Repetition Statements section, famous loops, one of the most important topics in any programming language.

Now is the time to put your knowledge into practice, this is where you will evolve, become a real programmer.

Solve the exercises, try, try, try again and again, before you see the solution, combined?
Just reading or watching videos will never make you a programmer, even the worser.

It is in the race, trying, struggling, breaking one's head, sweeping nights, and crying in a fetal position that one forges a true C++ Progressive programmer.

Left? Say goodbye to friends, girlfriend or boyfriend, family, social networks ... time to hide from society and exercise!

Ah ... and post there in the comments your solutions!

WHILE, DO WHILE, and FOR exercises in C++

0. Make a C++ program that asks the user for an integer, and displays their multiplication table.
Multiplication table with FOR, WHILE and DO WHILE

1. Make a program that takes two integers and generates the integers that fall within their range.

2. Make a program that asks for a grade between zero and ten. Show a message if the value is invalid and keep asking until the user enters a valid value.

3. Make a program that prints numbers 1 to 20 on the screen, one below the other. Then modify the program so that it shows the numbers next to each other.

4. Write programs that display the following patterns on the screen according to the number you provide, which will always be the number of lines:
(Solutions in e-book)
4.1

** 
*** 
**** 
*****

4.2
1
12 
123 
1234 
12345

4.3
1                                                                                                             
22                                                                                                      
333                                                                                                         
4444                                                                                                         
55555 


4.4
1                                                                                  
2 3                                                                                                         
4 5 6                                                                                                       
7 8 9 10 


4.5
       1                                                           
      2 3                                                           
     4 5 6                                                         
    7 8 9 10

4.6
        *                                                           
       * *                                                         
      * * *                                                         
     * * * *                                                       
    * * * * *

4.7
1                                                                      
01                                                                     
101                                                                    
0101                                                                   
10101

4.8
    *                                                                  
   ***                                                                 
  *****                                                                
 *******                                                               
*********                                                              
 *******                                                               
  *****                                                                
   ***                                                                 
    *


4.9
          1                                                            
        1   1                                                          
      1   2   1                                                        
    1   3   3   1                                                      
  1   4   6   4   1 

4.10                                                                      
1   1                                                                  
1   2   1                                                              
1   3   3   1                                                          
1   4   6   4   1                                                      
1   5   10   10   5   1                                                
1   6   15   20   15   6   1

4.11
12345                                                                                                         
2345                                                                                                          
345                                                                                                           
45                                                                                                            
5

4.12
12345                                                                                                         
 1234                                                                                                         
  123                                                                                                         
   12                                                                                                         
    1

4.13
5 4 3 2 1                                                              
4 3 2 1                                                                
3 2 1                                                                  
2 1                                                                    
1

4.14
    1                                                                  
   21                                                                  
  321                                                                  
 4321                                                                  
54321

4.15
     1234567654321                                                                                            
      12345654321                                                                                             
       123454321                                                                                              
        1234321                                                                                               
         12321                                                                                                
          121                                                                                                 
           1

5. Make a program that reads 5 numbers and reports the largest number.

6. Make a program that reads 5 numbers and gives the sum and average of the numbers.

7. Make a program that calculates the show the arithmetic average of N grades.

8. Make a program that prints only odd numbers between 1 and 50 on the screen. At the end, also show the sum of the numbers.

9. Create a program that asks the user for a number and calculates the summation to that value.

10. Create a program that asks the user for a number, and calculates its factorial. Ex .: 5! = 5.4.3.2.1 = 120
Summation and Factorial

11. The Fibonacci series is formed by the sequence 0,1,1,2,3,5,8,13,21,34,55, ... where the next term is always the sum of the previous two. Make a program capable of generating the series to the nth term that the user must supply.
Fibonacci in C++ with loopings

12. Make a program that asks for two numbers, base and exponent, calculate and display the first number raised to the second number. Do not use the power function of language.
Exponentiation with loopings in C++

13. Make a program that asks for an integer and determines whether or not it is a prime number. A prime number is one that is divisible only by itself and by 1.

14. Make a program that shows all primes between 1 and N where N is a user-supplied integer.
Prime numbers with C++

15. Make a program that displays all possible Powerball game combinations.
Powerball lottery in C++

16. Program software that receives a user number and tells you if it is a perfect number or not. Search Google for a perfect number.

17. Program software that receives two integers from the user, and tell them the greatest common divisor of these numbers.

18. Program a software that receives a number less than 1000, and say the value of the unit, the dozen, and the hundred digits.

19. Program software that calculates the sum of the digits of a number.

20. Make a program that shows the following Series terms:

  S = 1/1 + 2/3 + 3/5 + 4/7 + 5/9 + ... + n / m.

Print at the end the sum of the series.


21. Let the harmonic series H = 1 + 1/2 + 1/3 + 1/4 + ... + 1 / N, Make a program that calculates the value of H with N terms, where N is input by the user.

22. Make a program that shows the following terms of the Series:

  S = 1/1 + 2/3 + 3/5 + 4/7 + 5/9 + ... + n / m.

Print at the end the sum of the series.


23. The value of PI can be approximated by the following infinite sequence:
Infinite series to calculate pi
Create a program that calculates the value of this series with 10 terms, then 100 terms, and finally using a thousand terms. What values did you get?

No comments:

Post a Comment