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

Design an implement of the inputs functions for event mode

3204


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

4086


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

3410


To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

748


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 ?

2530


What is full form of PEPSI

2146


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

2277


how to test pierrot divisor

2481


write a program for area of circumference of shapes

2264


Sir... please give some important coding questions asked by product companies..

2047


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

3311


Write a routine to implement the polymarker function

4608


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

3416


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

3889


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

2588