Warning
This page is located in archive. Go to the latest version of this course pages.

Covid HW 01 - Simple C program

Write a program that:

  • is called triangle and the first lines of the program code contain information how to compile the code in the comment section.
  • has to have at least one input parameter passed in on the command line, e.g. ./triangle 10, the program will check if the parameter exist if not it will print an error message on the standard error output and ends. The same behaviour is expected for cases when the parameter is not a number.
  • print a triangle from asterisk (*) characters, where the first line has length equal to the value passed in as the first parameter of the program. The triangle is printed on the standard output.
  • than uses two loops for asterisk printing and the lines are printed in a subroutine.
  • that returns a number which represents a total number of stars printed on the standard output.

The example of the program behaviour when called as ./triangle 1

./triangle 1
*
echo $?
1

The example of the program behaviour when called as ./triangle 2

./triangle 2
**
*
echo $?
3

The example of the program behaviour when called as ./triangle 3

./triangle 3
***
**
*
echo $?
6

The example of the program behaviour when called as ./triangle 4

./triangle 4
****
***
**
*
echo $?
10

courses/be5b99cpl/hw/hw01c.txt · Last modified: 2020/09/23 16:36 by pacesp