Write a main program that declares and reads an array of  integers, and then sets to 0 the duplicated appearance of all its elements. (elements are different than 0)

Example:

If the entered array is:1, 7, 1, 3, 5, 1, 7
The array should become 1, 7, 0, 3, 5, 0, 0
Note: the value 1 and the value 7 are duplicated, and replaced by 0.


Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
#define SIZE 50

void main()
{
	int i, j, A[SIZE], dim;
	
	do{
		printf("Enter the dimension: ");
		scanf("%d",&dim);
	}while(dim<=0);

	for(i=0;i<dim;i++)
	{
		do{
			printf("A[%d]=",i);
			scanf("%d",&A[i]);
		}while(A[i]==0);
	}
	printf("BEFORE\n");
	for(i=0;i<dim;i++)
		printf("%d ",A[i]);
	printf("\n");
	
	for(i=1;i<dim;i++)
		for(j=0;j<i;j++)
			if(A[i]==A[j])
			{
				A[i]=0;
				break;
			}

	printf("AFTER\n");
	for(i=0;i<dim;i++)
		printf("%d ",A[i]);
	printf("\n");
		
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Checking palindrome words using functions