You are on page 1of 4

'C' Assignments

1. Using recursion calculate sum of digits of the 5-digit number


2. write a program to find whether a given year is a leap year or not
3. write a program to add first seven terms of the following series
1/1! + 2/2! + 3/3! + 4/4! + .........
4. write a program which will print factorial of a 2 or 3 digit number
5. write a program to print Fibonacci series
6. Write a C program to calculate the factorial of a number. Factorial function has to be written as a multi
line macro.
7. write a program to swap contents of two variables without using third variable
8. write a program to display all the vowels in a given line of text
9. write a program that converts uppercase to lowercase / lowercase to uppercase depending on the name it
is invoked with, as found in argv[1]
10. write a program to reverse the string. Stored in the following array of pointers to string
char *s[ ] = { we will teach you how to ,
move a mountain ,
level a building ,
erase the past ,
make a million ,
};
11. write a program to count the number of words, number of characters, number of blanks and number of
lines in a multiline string that ends with a full stop.
12. write a program to concatenate two strings using pointers
13. Design a function instring(char *str1, char *str2), where instring() searches out the existence of string str2
in str1 and reports the same. It should also display the number of occurrences of str2 in str1. Implement
the function in a C code
14. write an efficient program that will check whether a given string is a palindrome or not (use pointers)
15. write a program which concatenates a string to the left of a given string
16. write a program xstrrev (string) which would reverse the contents of one string
17. write a program to pick up the largest number from any 5 row by 5 column matrix
18. write a program to obtain the determinant value of a 4*4 matrix

19. write a program which will produce the following output


1
212
32123
4321234
543212345
20. write a code segment to compare two strings using pointers and arrays
21. A C program contains the following declaration
int x[8] = {10,20,30,40,50,60,70,80}
a) What is the meaning of x?
b) What is the meaning of (x+2)?
c) What is the value of *x?
d) What is the value of (*x +2)?
e) What is the value of *(x +2)?
22. A C program contains the following declaration
float table[2][3] = {{1.1,2.2,3.3},{4.4,5.5,6.6}}
a) What is the value of table?
b) What is the value of (table + 1)?
c) What is the value of *(table + 1)?
d) What is the value of *(*(table + 1)+1)?
e) What is the value of *(*(table + 1)?
23. A C program contains the following declaration
char *color[6] = {red, green, blue, white, black, yellow}
a) What is the meaning of color?
b) What is the meaning of (color +2)?
c) what is the value of *color?
d) How do color[5] and *(color + 5) differ?
24. write a code to swap even positioned characters with odd positioned characters in a given string and
change the case to UPPERcase if string is in lowercase or viceversa.
25. write a code to display length of string
26. Write a menu driven application that performs the functions of a calculator. The inputs from the user
should be validated and error messages in case inputs are not valid, should be displayed on screen. The
minimum operations expected are addition, subtraction, multiplication, division, factorials (use recursion)
and squares. Modularize the code if possible. Put the different (like add, subtract etc.) functions into
separate .c files and create one of your own header file for declaration of your function.
27. write a program that will concatenate two files, that is append the contents of one file at the end of
another file and write the results into a third file. You must be able to execute command as follows:
CONCAT file1.txt file2.txt target.txt
28. Write a program to search a given string in a given text file
29. Write a C program with a recursive function reverse(s), which reverses the string s.

30. Write a program which has 3 functions named ADD, SUB and MUL which will do addition, subtraction
and multiplication respectively. Use command line to call the functions.
31. write a program that copies the contents of one file into another. The names of the existing file and the
new file have to be accepted as command line arguments
32. write a program to display number of occurrences of a given character in a file
33. write a program to remove all blank lines from a file
34. write a program to display statistics of a file (No: of characters, No: of words, No: of lines)
35. Consider a text file. Copy its contents to an output file such that each line in the output file contain only
50 characters.
36. Design the 'find and replace' functionality of any standard editor. Write functions to perform the
functionality in a header file and a program to demonstrate in a C program
37. Write a function to write directly on screen without using printf()
38. write a function to print the ascii equivalent of all characters in a string
39. write a function atof() that converts a string s to double d
40. There are 100 records present in a file with the following structure:
struct product
{
char itemcode[6];
char itemname[20];
int qty;
};
write a program to read these records and arrange them in ascending order of itemcode and write them into a
target file.
41. Write a program that will reverse each line in a file and store it in another file
42. Write a program to find out difference in days between any two dates.
43. Write a program to display binary equivalent of a given decimal number
44. Write a program to display decimal equivalent of a given binary number
45. Write a program to display hex equivalent of a given binary number
46. Write a program to display decimal equivalent of a given hex number
47. Write a program to display binary equivalent of a given hex number
48. Write a program to sort a list of strings
49. write a program to multiply two matrices

50. Write a program in which define 'a' as an unsigned integer whose value is 0xa2c3 (hexadecimal). Write
the corresponding bit pattern for this value. Then evaluate each of the following bitwise expressions, first
showing the resulting bit pattern and then the equivalent hexadecimal value. Utilise the original value of
'a' in each expression. Assume that 'a' is stored in a 16 bit word.
a) ~a
b) a ^ 0x3f06
c) a | 0x3f06
d) a >> 3
e) a << 5
f) a ^ ~a
g) a ^~a
h) a | ~a
i) (a & ~0x3f06) << 8)
j) a & ~(0x3f06 >> 8)
51. Write a program to encrypt a string and decrypt it using your own method of encryption and decryption.
52. Write a program to remove all the comments from a 'C' program.
53. Use bit manipulation to write following program :
create a structure which is having 3 variables var1, var2 and var3. var1 is of 2 bits, var2 is of 2 bits and
var3 is of 3 bits. Do add and multiplication over var1 and var2 and store result in var3 and print that
value. What is the problem are you getting in the result? How this problem can be resolved? Take input as
a command line argument.
54. Write a program to know which endianess does your system support
55. Write a C program that will illustrate the equivalence between
a) Shifting a binary number to the left n bits and multiplying the binary number by 2n
b) Shifting a binary number to the right n bits and dividing the binary number by 2n.
Choose the initial binary number carefully, so that bits will not be lost as a result of the shifting operation.
56. Write a program to reverse the byte order of given value. Reversing of byte order means to change the
endianess of data.
57. Write a endianess independent code in C.
58. Write a C program which is having ADD, SUB, and MUL as three functions. Implement conditional
compilation to access at a time one function among the three.
59. For the question number 22, compile a static library that will include all the calculator function's .o files
and then compile and execute the calculator.
60. Write a program of 'Match stick game' between the computer and a user. Your program should ensure that
the computer always wins.
Rules for the game are as follows:
- there are 21 match sticks
- the computer asks the player to pick 1,2,3 or 4 match sticks
- after the person picks, the computer does its picking
- whoever is forced to pick up the last matchstick losses the game.