MC102

Computer Algorithms and Programming

Second List of Exercises

The exercises on this list cover classes until 09/03.
  1. Make a program that reads the number n on the keyboard and then read n numbers. The program must inform if the numbers are in increasing, decreasing sequence or none of the previous alternatives.
  2. Make a program that reads two dates from the keyboard. For each date, the user must be asked individually the day, month and year. The program must print the dates in chronological order.
  3. Make a program that reads two dates from the keyboard. For each date, the user must be asked individually the day, month and year. The program should print the difference in days between the dates.
  4. Make a program that reads sequences of three numbers: a, b e c and solve the second degree equation given by y = ax2+ b.x + c, printing its roots or a message indicating that the equation has no real root. The program must repeat these steps until the user enters the value 0 (zero) for the three entries.
  5. Make a program that reads three numbers: a, b e c and indicate whether these numbers can be the sizes of the sides of a triangle. If the answer is affirmative, indicate whether the triangle is equilateral (3 equal sides), isosceles (2 equal sides) or scalene (3 different sides). The three numbers do not represent the sides of a triangle when one is greater than the sum of the other two.
  6. Make a program that reads the number n on the keyboard and print all of its numbers backwards. Ex .: The number 1467 must be printed as 7641.
  7. Make a program that reads a number n on the keyboard and then read n numbers and place them in a vector. Set an upper limit for n so as not to exceed the size of the vector and check your program so that the user does not enter an invalid value for n. After reading is finished, print all the values ​​read in the same order in which they were entered.
  8. Make a program similar to the previous one, but print the numbers in the reverse order of typing.
  9. Make a program similar to the previous one, but that prints only the smallest and the largest number of the vector.
  10. Make a program similar to the previous one, but print out the average of the numbers, how many numbers are above the average and how many are below the average.
  11. Make a program similar to the previous one, but print all the numbers in ascending order.
  12. Make a program similar to the previous one, but that will print all the numbers in descending order.
  13. Make a program that uses the function Random to generate 1000 random numbers and save them in a vector. Order the vector. Read a number kick on the keyboard and inform whether or not this number is in the vector. Use binary search to find the number.
  14. Make a program that reads a number n and then read two vectors (A e B) in n elements. Limit the size of n and do not let the user enter a number outside the limit. After reading, calculate the vector value C as being the sum of the elements of A e B two by two (with the same indexes). Print vector C.(C [i] = A [i] + B [i]).
  15. Make a program similar to the previous one, just use the following formula to C: C [i] = A [i-1] + A [i] + B [i] + B [i + 1]. Beware of the vector limits. Assume that nonexistent index elements have a value of 0 (zero).