Skip to content

Instantly share code, notes, and snippets.

@kmbenjel
Last active July 28, 2024 16:42
Show Gist options
  • Save kmbenjel/bc3abdb9a1bfc490ff2eda27f4462470 to your computer and use it in GitHub Desktop.
Save kmbenjel/bc3abdb9a1bfc490ff2eda27f4462470 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void print_tab(int *tab, int size);
void ft_swap(int *a, int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
void ft_rev_int_tab(int *tab, int size)
{
int i;
i = 0;
while (i < size - 1 - i)
{
ft_swap(&tab[i], &tab[size - 1 - i]);
i++;
}
}
void print_tab(int *tab, int size)
{
int i;
for(i = 0; i < size; i++)
{
printf("%d", tab[i]);
i != size - 1 ? printf(", ") : printf(".\n");
}
}
int main(void)
{
int tab[10] = {1, 22, 333, 4444, 55555, 666666, 7777777};
print_tab(tab, 7);
ft_rev_int_tab(tab, 7);
print_tab(tab, 7);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment