Given a string s1 and a string s2, write a snippet to say whether s2 is a
rotation of s1 using only one call to strstr routine?
(eg given s1 = ABCD and s2 = CDAB, return true,
given s1 = ABCD, and s2 = ACBD , return false)
I hope this will work:
strcpy (s3,s1); //s3 = ABCDstrcat (s1,s3); // s1 = ABCDABCDthen check for strstr(s1,s2);
Write an efficient C program to count the number of bits set in an
unsigned integer.
i/p o/p
==== ===
0(00) 0
1(01) 1
2(10) 1
3(11) 2
..... ...
Ans:
int count_bit_set(unsigned int b)
{
int count =0;
while(b) {
b = b & (b-1);
count++;
}
return count;
}
int main()
{
int i, n = 20;
for (i = 0; i < n; i--)
printf("*");
return 0;
}
Change/add only one character and print '*' exactly 20 times.
(there are atleast 3 solutions to this problem :-)
I got TWO:
1.for (i = 0; i < n--)
2.for (i = 0; i + n; i--)
http://www.gowrikumar.com/programming/index.html
http://www.gowrikumar.com/