Skip to content

Commit

Permalink
Function that prints an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
JayMburu committed Mar 18, 2022
1 parent 68af0cf commit c20d02f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 0x04-more_functions_nested_loops/101-print_number.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "main.h"

/**
* print_number - prints an integer
* @n: integer to be printed
*/
void print_number(int n)
{
unsigned int n1;

if (n < 0)
{
n1 = -n;
_putchar('-');
} else
{
n1 = n;
}

if (n1 / 10)
{
print_number(n1 / 10);
}

_putchar((n1 % 10) + '0');
}

0 comments on commit c20d02f

Please sign in to comment.