A array contains dissimilar element how can we count,
and
A array contains dissimilar element how can we store in
another array with out repetition.
Answer Posted / vadivel t
Hi this code ll work for the second question but first
question i dint understand...
here in souce buff we have 16 nos, in which 1 to 5 repeats
3 times.
but at the end of the program u ll get only nos 1 to 6 as
out in dest buff without duplicate.
Note: Compiler used Visual studio 2005.
#include<stdio.h>
#include<conio.h>
void main()
{
int source[16] = {5,3,4,1,2,1,2,3,4,5,2,3,1,5,4,6};
int dest[6], i, j, count = 0, flag;
int test = 0;
/*Copy the first element*/
dest[0] = source[0];
count++;
for(i = 1; i<= 15; i++)
{
/*Check whether the same element is already
available in the dest buff*/
for(j = 0; j<count; j++)
{
if(dest[j] == source[i])
{
/*Already available*/
flag = 0;
break;
}
else
{
flag = 1;
}
}
if(flag == 1)
{
/*The same element is not available
already - so copy it to the dest buffer*/
dest[count] = source[i];
count++;
}
}
for(i = 0; i<=5; i++)
printf("%d\t",dest[i]);
_getch();
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is the explanation for cyclic nature of data types in c?
What is the use of a conditional inclusion statement in C?
What are the types of pointers?
What is the advantage of using #define to declare a constant?
Why does everyone say not to use scanf? What should I use instead?
Explain the difference between the local variable and global variable in c?
What is cohesion in c?
How many types of operators are there in c?
Explain high-order bytes.
What is meant by 'bit masking'?
What are the advantages of using linked list for tree construction?
What is getche() function?
How can you call a function, given its name as a string?
write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.
Should a function contain a return statement if it does not return a value?