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
What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?
Write a program to model an exploding firecracker in the xy plane using a particle system
What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql
how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns
How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?
Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange
#include
What is data _null_? ,Explain with code when u need to use it in data step programming ?
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.
could you please send the program code for multiplying sparse matrix in c????
How to palindrom string in c language?
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 ?
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
Cluster head selection in Wireless Sensor Network using C programming language.
write a simple calculator c program to perform addition, subtraction, mul and div.