Skip to content

Instantly share code, notes, and snippets.

@RianWardana
Created September 25, 2017 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RianWardana/9c01a33c3d077ed9bfa23a249869b3bb to your computer and use it in GitHub Desktop.
Save RianWardana/9c01a33c3d077ed9bfa23a249869b3bb to your computer and use it in GitHub Desktop.
// Nurian S Wardana
// Modify array + hapus duplikasi
#include <stdio.h>
void gantiIsiArray(int array[], int arrayLength) {
printf("Array menjadi: ");
int n;
for(n = 0; n < arrayLength; n++) {
array[n] = array[n] * 2;
printf("%d ", array[n]);
}
}
void hapusDuplikasi(int array[], int arrayLength) {
int n;
int j;
int i = 1;
for (j = 1; j < arrayLength; j++) {
if (array[j] != array[j-1]) {
array[i] = array[j];
i++;
}
}
for(n = i; n < arrayLength; n++) {
array[n] = 0;
}
printf("\nSetelah dihapus duplikasi menjadi: ");
for(n = 0; n < arrayLength; n++) {
printf("%d ", array[n]);
}
}
int main() {
int numbers[] = {1,2,3,4,5,6};
int numbersLength = sizeof(numbers) / sizeof(int);
int duplicates[] = {10,10,10,11,11,12,13,15,16};
int duplicatesLength = sizeof(duplicates) / sizeof(int);
printf("Array awal: ");
int n;
for(n = 0; n < numbersLength; n++) {
printf("%d ", numbers[n]);
}
printf("\n");
gantiIsiArray(numbers, numbersLength);
hapusDuplikasi(duplicates, duplicatesLength);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment