C Programming Assignment List-2020
C Programming Assignment List-2020
1. Develop a C program to perform operations (+,*,-, / and %) on two whole numbers. Identify
suitable data types to represent the numbers and resultant values
2. Develop a C program to add two operands and store the result in one of the operands using
addition assignment operator.
3. Write a C program to find the maximum of 2 numbers using Conditional operator.
4. Write a menu based C program to perform operations (+, - and *) on matrices.
5. Write a program to perform operations on complex numbers.
6. Write a program to find whether the given processor is little endian or big endian.
7. Write a program to find out the difference in days between any two dates. It must work
regardless of the year, month and day. Consider Leap years while calculating the difference.
1. Develop a C program to calculate simple interest using the formula I=PTR/100. Display
Interest with two digit precision after decimal point
Control Sequence
3. Develop a C program which adds all numbers from 1 to N, except those which are divisible
by 5. Implement this using for loop and continue statement.
4. Develop a C program to find factorial of a number N using for loop.
5. Develop a C program to find the sum of all odd numbers upto N using a while loop.
6. Write a program to print ASCII values of upper case and lower case alphabets and digits
(A-Z, a-z and 0-9).
7. Write a Program to find if a given number is Armstrong number.
Hint: (153 = 1^3 + 5^3 + 3^3)
11. Write a program to search for an element in a given list of elements. Use break statement.
12. Write a program to print all the prime numbers in the first N numbers.
13. Write a program to find the sum of digits of a given number.
14. Write a C program to generate two Relatively Prime numbers. Two integers are relatively
prime (or coprime) if there is no integer greater than one that divides them both (that is,
their greatest common divisor is one). For example, 12 and 13 are relatively prime, but 12
and 14 are not.
15. Write a program to generate Random number
● Any
● Prime number
● Two Relatively Prime Numbers
1. Develop multi file program to understand static, auto, register, global, static global
variables.What is the scope and lifetime of each of these types of variables.
2. Write a program to demonstrate the difference between static vs auto.
3. Write a program to demonstrate the difference between static vs extern.
4. Write a program to demonstrate the difference between auto vs register.
5. Why do we need to declare a variable as a register and what happens if we declare variable
as a register.
6. Write a program to demonstrate difference between global variables vs local variables and
in which section they are stored.
7. Write a C program to check what happens if we declare a variable as static in global
declaration and also in local declaration. (And write down the observations as a comment
part in your program).
Arrays
1. Write a program to read your name into a character array. Print the name along with the
length of your name and sizeof the array in which name is stored.
2. Use scanf function to read a string of characters (into character type array called text)
including alphabets, digits, blanks, tabs etc except new line character. Write a loop that will
examine each character in a character-type array and determine how many of the
characters are letters, how many are digits, how many are blanks and how many are tabs.
Assume that text contains 80 characters.
3. Write a program that reads a number that says how many integer numbers are to be stored
in an array, creates an array to fit the exact size of the data and then reads in that many
numbers into the array.
4. Program to print array in reverse order
5. Program to Calculate Sum and Average of an array
6. Program to find the largest, smallest, second largest and second smallest element of an
array
7. Program to copy an array to another array in same order & in reverse order
8. Program to insert an element in a Specified Position in given array
9. Program to delete the specified Integer from an array
10. Program to Put Even & Odd elements of an array in two separate arrays
11. Program to concatenate two arrays
12. Program to find the Largest number in an array of numbers using recursion
13. Program to print all the repeated numbers with frequency in an Array.
Functions
Pointers
1. A C program contains the following declaration
int x[8]= {10,20,30,40,50,60,70,80};
● What is the meaning of x?
● What is the meaning of (x+2)?
● What is the value of *x?
● What is the value of (*x+2)?
● What is the value of *(x+2)?.
2. A C program contains the following declaration
float table[2][3] = { { 1.1,1.2,1.3},{2.1,2.2,2.3}};
● What is the meaning of a table?
● What is the meaning of (table+1)?
● What is the meaning of *(table+1)?
● What is the meaning of (*(table+1)+1)?
● What is the meaning of (*(table)+1)?
● What is the value of *(*(table+1) +1)?
● What is the value of *(*(table)+1)?
● What is the value of *(*(table+1)?
● What is the value of *(*(table) + 1)+1?
3. A C program contains the following declaration
char *color[6] = {“red”, “green”, “blue”, “white”, “black”, “yellow”};
● What is the meaning of color?
● What is the meaning of (color+2);
● What is the value of *color?
● What is the value of *(color+2)?
● How do color[5] and *(color + 5) differ?.
4. Write a program to count the number of ‘e’ in the following array of pointer to the string.
char * s [ ] = {
“we will teach you how to “ ;
“Move a mountain “ ;
“Level a building “ ;
“Erase the past “;
“Make a million “ ;
}.
5. Write a function ``replace'' which takes a pointer to a string as a parameter, which replaces
all spaces in that string by minus signs, and delivers the number of spaces it replaced.
Thus
char *cat = "The cat sat";
n = replace( cat );
should set
cat to "The-cat-sat"
and
n to 2.
Strings
1. Write a program to convert lower case string to upper case string and vice versa.
2. Write a program to reverse a string using recursive functions
3. Write a program to read n number of strings using a two-dimensional character array, sort
them and display the sorted list of strings on the screen.
4. Write a program to read n number of strings and display them on the screen. Use array of
pointers and dynamic memory allocation techniques.
5. Write a C program with a function any (s1, s2). This function returns the first location
(index of location) in the string s1 which matches with any string in s2 otherwise.
6. Write a C program with a function delete (s1, c). This function deletes each character in s1
which matches character c.
7. Write a Program to implement strtok library function.
8. Write a C program with a function deletes2 (s1, s2). This function deletes each character in
string s1 which matches any character in string s2.
9. Write a function expand (s, t) which converts characters like newline and tab into visible
escape sequences like \n and \t as it copies the string s to t. Use switch statement and also
display both s and t at the end.
10. Write a function expand (s1, s2) which expands shorthand notations of s1 like a-d into abcd
and 0-9 to 0123456789 in s2. For example if the string in s1 is 0123a-e1-4 then s1 is
expanded in s2 to 0123abcde1234.
11. Write a program to print out all rotations of a string typed in. For eg:if the input is “Space”,
the output should be: space paces acesp cespa espac.
12. Implement string library functions. strrev, strcpy, strcat, strcmp with same return values
and all error handling features using pointers.
1. Write a program to represent time of the day in hrs, mins and secs. Use structures.
2. Define structure with two members (one int and other char). Also define s union with two
members (one int and other char). Print the sizes of structure and union in number of bytes.
3. Define a structure declaration for each of the following situations. Assume a 16-bit integer
word
1. Define three bit fields, called a, b and c, whose widths are 6-bits, 4-bits and 6-bits,
respectively
2. Declare a structure-type variable v having the composition defined in part (a) above.
Assign initial values 3, 5 and 7 respectively, to the three bit fields. Are the bit fields
large enough to accommodate these values?
3. What are the largest values that can be assigned to each of the bit fields defined in
part (a) above?
4. Define three bit fields, called a, b and c, whose widths are 8 bits, 6 bits and 5 bits,
respectively. How will these fields be stored within the computer’s memory?
5. Define three bit fields, called a, b and c, whose widths are 8 bits, 6 bits and 5-bits
respectively. Separate a and b with 2 vacant bits.
4. Develop a program to generate marks sheet of C-DAC, Hyderabad Students (DSSD, DESD
and DAC courses). Modules are different for each course. Implement this using structures,
unions, arrays, loops and variables.
5. Write a program to search for a given element in a list of elements using Linear Search. Use
flag to represent the status of search. Define flag as an enumeration variable whose value is
either true or false.
6. Write a menu driven C program to perform operations on Complex numbers. Use
enumeration data type to identify the different operations on Complex numbers.
1. Experiment to find out what happens when printf argument string contains \x, where x is
some character (a, b, c, \, ^ etc). What are your observations?
2. Write a program to remove all the comments from a ‘C’ program.
3. 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 at DOS prompt as follows:
C > CONCAT Source 1.txt source 2.txt Target.txt.
4. Write a c program to print the same file on the console.
5. Write a C program to open a file and store text (character type data) in one’s complement
form. Read the contents from the file and display as it is as well in one’s complement form.
Use command line arguments to pass file name to your C program.
6. Write a program which reads a line of characters. Each character entered from the keyboard
is tested to determine its case, and is then written to the data file in the opposite case.
Display the contents of the file. Also use ftell and fseek to determine the current file position
and to change the file position.
7. Write a program to embed assembly language code in C program
9. Given as input a floating (real) number of centimeters, print out the equivalent number of
feet (integer) and inches (floating, 1 decimal), with the inches given to an accuracy of one
decimal place.
Assume 2.54 centimeters per inch, and 12 inches per foot.
If the input value is 333.3, the output format should be:
333.3 centimeters is 10 feet 11.2 inches.
10. Given as input an integer number of seconds, print as output the equivalent time in hours,
minutes and seconds. Recommended output format is something like 7322 seconds is
equivalent to 2 hours 2 minutes 2 seconds.
11. Write a program to list the files given as arguments, stopping every 20 lines until a key is
hit.(a simple version of more UNIX utility)
Bitwise Operations
If the masking operation is selected, prompt the user for the type of operation (bitwise and,
bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit
shifting operation is selected, prompt the user for the type of shift (left to right), and then
the number of bits.
Choose the initial binary number carefully, so that bits will not be lost as a result of the
shifting operation.
Preprocessor