vadivel


{ City } coimbatore
< Country > india
* Profession * student
User No # 17527
Total Questions Posted # 1
Total Answers Posted # 6

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

Users Marked my Answers as Correct # 151
Users Marked my Answers as Wrong # 85
Questions / { vadivel }
Questions Answers Category Views Company eMail

To reverse an entire text file into another text file.... get d file names in cmd line

Subex,

C Code 2290




Answers / { vadivel }

Question { Google, 36020 }

Give a oneline C expression to test whether a number is a
power of 2?


Answer

# include

void main()
{
int n;
scanf("%d",&n);
if( n & (n-1) )
printf("Not a Power of 2");
else
printf("Power of 2");
}

Is This Answer Correct ?    48 Yes 5 No

Question { Infosys, 35584 }

How do I write a program to print proper subset of given
string . Eg :input: abc
output:{},{a},{b},{c},{a,b},{a,c},{b,c},
{a,b,c}.I desperately need this program please mail me to
saravana6m@gmail.com


Answer

# include
# include
# include
# include
# include

int bin[16];
void genbin(int);

void main()
{
clrscr();
char *str;
int i=0,len=0;
str = (char*)malloc(100);
printf("Input a no. :");
scanf("%s",str);
len = pow(2,strlen(str));
for(i=0;i < len;i++)
{
genbin(i);
for(int j=0;j < strlen(str);j++)
{
if(bin[j] == 1)
printf("%c",str[j]);
}
printf("\n");
}
free(str);
getch();
}
void genbin(int n)
{
for(int i=0;i<8;i++)
{
bin[i] = n%2;
n /= 2;
}
}

Is This Answer Correct ?    3 Yes 0 No


Question { 4024 }

How can u say that a given point is in a triangle?
1. with the co-ordinates of the 3 vertices specified.
2. with only the co-ordinates of the top vertex given.


Answer

solution for 1st case:
Given:(x1,y1),(x2,y2),(x3,y3),the co-ordinates of the
vertices of the triangle.
Let (xx,yy) be the pt to be located.
Find the equations of the lines {(x1,y1),(x2,y2)} and
{(x1,y1)(x3,y3)} using the formula
((y-y1)/(y2-y1))=((x-x1)/(x2-x1))

Now substitute the y value in the 2 equations got. You 'll
be getting the x limits. If the given x value lies within
the limits you have found,the given pt is within the
triangle or else it is not.

Is This Answer Correct ?    5 Yes 0 No

Question { 35684 }

C program to find frequency of each character in a text
file?


Answer

#include
int count[26];
int main()
{
FILE *f;
int i;
char ch;
f = fopen("capti.c","r");
while(!feof(f))
{
ch = fgetc(f);
count[ch - 'a']++;
}
for(i = 0;i < 26;i++)
printf("count[%c] = %d\n",65+i,count[i]);
fclose(f);
return 0;
}
//asuming only lower characters are required

Is This Answer Correct ?    38 Yes 23 No

Question { Persistent, 50384 }

Write a program to remove the C comments(/* */) and C++
comments(//) from a file.
The file should be declared in command line.


Answer

#include
int main(int argc,char *argv[])
{
FILE *f;
int flag;
f = fopen(argv[1],"r");
while(!feof(f))
{
ch = fgetc(f),flag = 0;
if(ch == '/')
{
ch = fgetc(f);
if(ch == '*')
{
flag = 1;
while(1)
if(fgetc(f) == '*' && fgetc(f) == '/')
break;
}
else if(ch == '/')
{
flag = 1;
while(fgetc(f)!= '/n');
}
else
printf("/");// if it s division operator
}
if(!flag )
printf("%c",ch);
}
fclose(f);
}
/*
Run d prog as
>./a.out file_name.cpp
*/

Is This Answer Correct ?    54 Yes 47 No

Question { Subex, 11372 }

Find the middle node in the linked list??
(Note:Do not use for loop, count and count/2)


Answer

U mean without any looping statements r just for loop?????
It can be done in a single traversal using Hare n turtle
method as said above using a for or while loop.....
Without using looping statements d list can't be traversed..
Plz make the question clear.....

Is This Answer Correct ?    3 Yes 10 No