Wednesday, July 8, 2015

C Language : Challenging Algorithms

Bitwise Operators
1. Write a program to determine the ranges of char,short,int and long variables.

2. Write a function setbits(x,p,n,y)  that returns x with n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged.

3. Write a function invert(x,p,n) that return x with the n bits that begin at position p inverted(i.e 1 changed to 0 and vice versa), leaving the others unchanged.

4. Write a function rightrot(x,n) that returns the value of integer x rotated to right by n bit positions.

5. Write a faster bitcount(x) funtion to count the 1 bits in x.

6. How to reverse the bits in an interger?

Others
1. Write a macro to convert a character into lower case from uppercase.

2. Implement a memcpy function.

3. How to declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

4. How do you find the middle of a linked list? Write a C program to return the middle of a linked list.

5. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

6. Reversal of Linklist(with or without recursion)

7. Reverse the list without reversing the links.

8. Find a cycle/loop in a Linklist.

9. How to create an exact copy of a linked list.

10.Write a C program to return the nth node from the end of a linked list.

11.How would you find out if one of the pointers in a linked list is corrupted or not?

12.Write your own C program to implement the atoi() function. 

13.Implement the memmove() function. What is the difference between the memmove() and memcpy () function?

14.Write C code to implement the strstr() (search for a substring) function.

15.Write your own printf() function in C.

16.Write a C program to print a square matrix helically.

17.Write a C program to calculate pow(x,n)?

18.How do you calculate the maximum subarray of a list of numbers?

19.How to generate fibonacci numbers? How to find out if a given number is a fibonacci number or not? Write C programs to do both.

20.What Little-Endian and Big-Endian? How can I determine whether a machine's byte order is bigendian or little endian? How can we convert from one to another?

21.Write a C progam to convert from decimal to any base (binary, hex, oct etc...)

22.Write C code to check if an integer is a power of 2 or not in a single line?

23.Write a C program to find the GCD of two numbers.

24.Write C code to dynamically allocate one, two and three dimensional arrays (using malloc()).

25.How would you find the size of structure without using sizeof()?

26.Write a C program to multiply two matrices.





No comments:

Post a Comment