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

HW 01 - Simple C program

Write a program that:

  • is called triangle and the first lines of the code contain information how to compile the code (as comments).
  • 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 and end.
  • 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
  • that returns a number which represents a total number of stars printed on the standard output.

Dont forget that you can use the “atoi” function to convert strings to ints!

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_-_lab02.txt · Last modified: 2021/10/06 10:41 by brouggeo