Skip to content

Commit

Permalink
print numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakhinamammadzade committed Nov 26, 2023
1 parent aded260 commit 04480d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions variadic_functions/1-main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "variadic_functions.h"

/**
* main - check the code
*
* Return: Always 0.
*/
int main(void)
{
print_numbers(", ", 4, 0, 98, -1024, 402);
return (0);
}
27 changes: 27 additions & 0 deletions variadic_functions/1-print_numbers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "variadic_functions.h"
#include <stdarg.h>
#include <stdio.h>

/**
* print_numbers - function to print numbers
* @separator: string to separate numbers
* @n: number of arguments
* Return: void
*/
void print_numbers(const char *separator, const unsigned int n, ...)
{
unsigned int a;
va_list list;

va_start(list, n);
for (a = 0; a < n; a++)
{
printf("%d", va_arg(list, unsigned int));
if (a != (n - 1) && separator != 0)
{
printf("%s", separator);
}
}
printf("\n");
va_end(list);
}

0 comments on commit 04480d1

Please sign in to comment.