Write, efficient code for extracting unique elements from
a sorted list of array.

e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).

Answer Posted / msvinod

/*This c program aimed at printing the unique numbers in a
sorted array of repeating numbers.*/
#include<stdio.h>
main(){
int len=0,i=0,rep=0; /*Initializing the identifiers*/
printf("Enter length of array :--");
scanf("%d",&len); /*Input for array length*/
int arr[len]; /*Initializing array*/
for(i=0;i<len;i++){ /*Running loop for input of array
elements*/
printf("%dth element :--",i);
scanf("%d",&arr[i]);
}
rep=arr[0]; /*Assigning array first value to rep*/
printf("Unique array :-- [%d,",rep); /*Printing of array
starts here*/
for(i=0;i<len;i++){ /*Running loop to print all the
unique elements of array*/
if(arr[i]!=rep){
rep=arr[i]; /*Assaigning new value to rep*/
printf("%d,",rep);
}
}
printf("]\n"); /*Closing array output*/
}
/*THE END*/

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

3709


Write a program to model an exploding firecracker in the xy plane using a particle system

3686


What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql

2407


how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns

3117


How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?

2019






Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

2859


#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1067


What is data _null_? ,Explain with code when u need to use it in data step programming ?

2821


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

2136


could you please send the program code for multiplying sparse matrix in c????

3068


How to palindrom string in c language?

8843


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2259


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

2325


Cluster head selection in Wireless Sensor Network using C programming language.

3107


write a simple calculator c program to perform addition, subtraction, mul and div.

3143