mcahydguy


{ City } hyderabad
< Country > india
* Profession * se
User No # 13836
Total Questions Posted # 0
Total Answers Posted # 2

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 26
Users Marked my Answers as Wrong # 14
Questions / { mcahydguy }
Questions Answers Category Views Company eMail




Answers / { mcahydguy }

Question { TCS, 35131 }

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

main ()
{

int a[] = { 1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9 };
int i = 0, key;
int size;

size = sizeof (a) / sizeof (int);
key = a[i];

for (; i < size; i++)
{
if (key != a[i])
{
printf ("\n %d", a[i]);
key=a[i];
}
}
}

Is This Answer Correct ?    7 Yes 6 No

Question { 16439 }

How do you write a program which produces its own source
code as its output?


Answer

#include
main()
{
FILE *fd;
int c;

fd= fopen("./file.c","r");
while ( (c=fgetc(fd)) != EOF)
{
printf("%c", c);
}

fclose(fd);
}

Is This Answer Correct ?    19 Yes 8 No