Problem Description
Program to Delete duplicate elements from an arrayTest Case 1
Input (stdin)5 1 3 4 5 3
Expected Output1 3 4 5
Test Case 2
Input (stdin)3 1 3 3
Expected Output1 3
Program
#include <stdio.h> int main() { int arr[20], i, j, k, size; scanf("%d", &size); for (i = 0; i < size; i++) scanf("%d", &arr[i]); printf("\n"); for (i = 0; i < size; i++) { for (j = i + 1; j < size;) { if (arr[j] == arr[i]) { for (k = j; k < size; k++) { arr[k] = arr[k + 1]; } size--; } else j++; } } for (i = 0; i < size; i++) { printf("%d ", arr[i]); } return 0; }
No comments:
Post a Comment
Note: only a member of this blog may post a comment.