TASK-
Write a C program to print all Unique numbers in an array (the size of array (number of elements in array) should be taken from user)!!
STEPS :
- Ask user to enter the size of array
- store this size in a variable
- use this variable to declare an array of that size
- Finally ask for the entries of array
- Follow the algorithm explained below to find unique elements in that array
CODE:
#include <stdio.h>
int main()
{
int r,z;
printf("Enter the number of entries in array: ");
scanf("%d",&r);
int array[r];
printf("Enter entries: \n");
for (z=0;z<r;z++)
{
printf("Entry %d: ",z+1);
scanf("%d",&array[z]);
printf("\n");
}
int i,j;
int count = 1;
for(i = 0; i < r; i++){
for(j = 0; j < r; j++){
if(array[i] == array[j] && i != j)
break;
}
if(j == r ){
printf("\nunique elements in an array is [%d] : %d \n",count,array[i]);
++count;
}
}
getchar();
return 0;
}
EXPECTED OUTPUT:
wonderful piece of work
ReplyDelete