Programming C

Tasks studies - laboratory


Project maintained by dawidolko Hosted on GitHub Pages — Theme by dawidolko

Exam 3

Task 1.

Create a parameterless function called literaA() that displays the letter A on the screen, made up of letters A. The height of the letter A is read from the keyboard. Sample result:

     A
    A A
   A   A
  AAAAAAA
 A       A
A         A

Task 2.

Create a parameterless function max() that reads 10 integers (one at a time) from the keyboard. The function is to find the largest of the given numbers and print on the screen information about how many times the largest number appeared in the given sequence of numbers. The task should use a one-dimensional array of integers.

Task 3.**

Create the function zwiekszL(), which will accept an integer n (function parameter). The function is to read n real numbers from the keyboard (one at a time) and remember them. Then the function is to add 100 to each of the read numbers and print the values ​​of all numbers on the screen (after applying changes). In addition, the function is to return the sum of all read numbers (after increasing their values).

Task 4.

Create the function macierzTD(), which will accept an integer n (function parameter). The function is to create a two-dimensional array of dimensions n x n. Then the function is to fill the array in such a way that the values ​​10 are on the main diagonal of the array and below this diagonal, while the remaining cells of the array contain the number 1 (see example). To fill the array with the appropriate values, use 1 for loop and 1 do while loop. Then, the entire array should be printed on the screen in a clear way, i.e. columns separated by a tab character and each row of the table on a separate line. To print the contents of the table, use 1 do while loop and 1 for loop.

Example of a completed array for n=4:

10 1 1 1
10 10 1 1
10 10 10 1
10 10 10

Task 5.

Create a prototype of a function called fieldT, which will accept two real numbers a and h and return the area of ​​a triangle with a base length a and height h drawn to this base.

  1. In the main() function, each of the functions from tasks 1-4 should be called with the appropriate parameters (if they accept them) and the results returned by them should be printed (if the function returns something). In addition, each function call should be preceded by an appropriate message, which will be printed to the console. It is also necessary to ensure that the results printed to the screen are legible.

  2. Example code diagram in the main() function:

// Printing a message that the function from task 1 will be called, e.g.: "Calling function xxx"
// Calling the function from task 1 with the appropriate parameters and printing the results returned by it
// An empty line separating the function calls
// Printing a message that the function from task 2 will be called, e.g.: "Calling function yyy"
// Calling the function from task 2 with the appropriate parameters and printing the results returned by it
// An empty line separating the function calls, etc.