Skip to content

Latest commit

 

History

History

0x04-more_functions_nested_loops

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

0x04. C - More functions, more nested loops

Resources

Read or watch:

Learning Objectives

General

  • What are nested loops and how to use them
  • What is a function and how do you use functions
  • What is the difference between a declaration and a definition of a function
  • What is a prototype
  • Scope of variables
  • What are the gcc flags -Wall -Werror -pedantic -Wextra -std=gnu89
  • What are header files and how to to use them with #include

Tasks

0. isupper

  • Write a function that checks for uppercase character.

Requirements:

Prototype: int _isupper(int c); Returns 1 if c is uppercase Returns 0 otherwise

Mode: mandatory

File: 0-isupper.c


1. isdigit

  • Write a function that checks for a digit (0 through 9).

Requirements:

Prototype: int _isdigit(int c); Returns 1 if c is a digit Returns 0 otherwise

Mode: mandatory

File: 1-isdigit.c


2. Collaboration is multiplication

  • Write a function that multiplies two integers.

Requirements:

Prototype: int mul(int a, int b);

Mode: mandatory

File: 2-mul.c


3. The numbers speak for themselves

  • Write a function that prints the numbers, from 0 to 9, followed by a new line.

Requirements:

Prototype: void print_numbers(void); You can only use _putchar twice in your code

Mode: mandatory

File: 3-print_numbers.c


4. I believe in numbers and signs

  • Write a function that prints the numbers, from 0 to 9, followed by a new line.

Requirements:

Prototype: void print_most_numbers(void); Do not print 2 and 4 You can only use _putchar twice in your code

Mode: mandatory

File: 4-print_most_numbers.c


5. Numbers constitute the only universal language

  • Write a function that prints 10 times the numbers, from 0 to 14, followed by a new line.

Requirements:

Prototype: void more_numbers(void); You can only use _putchar three times in your code

Mode: mandatory

File: 5-more_numbers.c


6. The shortest distance between two points is a straight line

  • Write a function that draws a straight line in the terminal.

Requirements:

Prototype: void print_line(int n); You can only use putchar function to print Where n is the number of times the character should be printed The line should end with a \n If n is 0 or less, the function should only print \n

Mode: mandatory

File: 6-print_line.c


7. I feel like I am diagonally parked in a parallel universe

  • Write a function that draws a diagonal line on the terminal.

Requirements:

Prototype: void print_diagonal(int n); You can only use _putchar function to print Where n is the number of times the character </code> should be printed The diagonal should end with a \n If n is 0 or less, the function should only print a \n

Mode: mandatory

File: 7-print_diagonal.c


8. You are so much sunshine in every square inch

  • Write a function that prints a square, followed by a new line.

Requirements:

Prototype: void print_square(int size); You can only use _putchar function to print Where size is the size of the square If size is 0 or less, the function should print only a new line Use the character # to print the square

Mode: mandatory

File: 8-print_square.c


9. Fizz-Buzz

  • The “Fizz-Buzz test” is an interview question designed to help filter out the 99.5% of programming job candidates who can’t seem to program their way out of a wet paper bag.

Requirements:

Each number or word should be separated by a space You are allowed to use the standard library

Mode: mandatory

File: 9-fizz_buzz.c


10. Triangles

  • Write a function that prints a triangle, followed by a new line.

Requirements:

Prototype: void print_triangle(int size); You can only use _putchar function to print Where size is the size of the triangle If size is 0 or less, the function should print only a new line Use the character # to print the triangle

Mode: mandatory

File: 10-print_triangle.c


11. The problem of distinguishing prime numbers from composite numbers and of resolving the latter into their prime factors is known to be one of the most important and useful in arithmetic

  • The prime factors of 1231952 are 2, 2, 2, 2, 37 and 2081.

Requirements:

You are allowed to use the standard library Your program will be compiled with this command: gcc -Wall -pedantic -Werror -Wextra -std=gnu89 100-prime_factor.c -o 100-prime_factor -lm

Mode: #advanced

File: 100-prime_factor.c


12. Numbers have life; they're not just symbols on paper

  • Write a function that prints an integer.

Requirements:

Prototype: void print_number(int n); You can only use _putchar function to print You are not allowed to use long You are not allowed to use arrays or pointers You are not allowed to hard-code special values

Mode: #advanced

File: 101-print_number.c