Skip to content

Instantly share code, notes, and snippets.

@pfactum
Created December 12, 2012 00:36
Show Gist options
  • Save pfactum/4263788 to your computer and use it in GitHub Desktop.
Save pfactum/4263788 to your computer and use it in GitHub Desktop.
Silly lab for ITS :)
#include <stdio.h>
#include <sysexits.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
unsigned int array_size;
printf("Enter array size: ");
scanf("%u", &array_size);
int a[array_size];
for (unsigned int i = 0; i < array_size; i++)
{
printf("Enter array element #%d: ", i);
scanf("%d", &a[i]);
}
int *b = NULL;
unsigned int size = 0;
for (unsigned int i = 0; i < array_size; i++)
{
unsigned int found = 0;
for (unsigned int j = 0; j < size; j++)
if (*(b + j) == a[i])
found++;
if (found == 0)
{
b = realloc(b, (++size) * sizeof(int));
*(b + size - 1) = a[i];
}
}
for (unsigned int i = 0; i < size; i++)
printf("%d\n", *(b + i));
free(b);
return EX_OK;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment