100% found this document useful (1 vote)
368 views8 pages

C Programming Assignment List-2020

The document outlines a list of programming assignments related to various C programming concepts including: 1. Operators and operands, control flow, basic data types, arrays, functions, pointers, and strings. The assignments involve writing programs to perform mathematical operations, control logic, work with different data types, manipulate arrays, define and call functions, use pointers, and handle strings. 2. Many assignments require using various C programming elements like operators, data types, loops, conditional statements, functions, arrays and pointers to complete tasks like calculating interest, finding maximum of numbers, generating patterns, searching/sorting arrays, string manipulation and more. 3. The assignments are divided into different sections based on the main C concept
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (1 vote)
368 views8 pages

C Programming Assignment List-2020

The document outlines a list of programming assignments related to various C programming concepts including: 1. Operators and operands, control flow, basic data types, arrays, functions, pointers, and strings. The assignments involve writing programs to perform mathematical operations, control logic, work with different data types, manipulate arrays, define and call functions, use pointers, and handle strings. 2. Many assignments require using various C programming elements like operators, data types, loops, conditional statements, functions, arrays and pointers to complete tasks like calculating interest, finding maximum of numbers, generating patterns, searching/sorting arrays, string manipulation and more. 3. The assignments are divided into different sections based on the main C concept
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

C Programming Assignment List

Operators and Operands

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.

Basic Data Types

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

1. Develop a C program having following logic. If i is 20 or j is 20, display as “Atleast one


variable is having 20” otherwise display “Both variables are not having 20”. If i is less than
or equal to 40 and j is less than or equal to 40, It should display “Both are less than or equal
to 40” otherwise, it should display as “Both are not less than or equal to 40”. Implement this
using if-else statement as well as with conditional operator.
2. Develop a C program which accepts character type data items from users. In case if user
typed
‘A’ or ‘a’, it should display ​A for Apple
‘B’ or ‘b’, it should display ​B for Bat
‘D’ or ‘d’, it should display ​D for Dog
‘F’ or ‘f’, it should display ​F for Fan
Instead of the above 4 characters, if a user types any other character, it should display
“​Character ​is not in the range”. ​Implement this using if-else statement ​and switch
statement.

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)

8. Write a program to find whether the given number is palindrome or not.Palindrome is a


number that remains the same when its digits are reversed. Example 16461
9. Write a menu based C program to perform operations (+, - and *) on matrices.
10. Generate the following pyramid of numbers using nested loops
1
212
32123
4321234
543212345

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

Storage Class Specifiers

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

1. Write a program to calculate n!/(n-r)! using functions.


2. Write a recursive function to find the factorial of a number.
3. Write a function to swap contents of two variables using functions and pointer variables.
4. Write a C program with a function rotoate_right (n, b). This function rotates integer n
towards right by b positions. 
6. Write a C program with a function invertponwards (n, p, b). This function inverts b bits of
integer n, that begin at position p, leaving the others unchanged. 
7. Write a C program with a function ​tolower​, which converts upper case letters to lower case.
Use conditional expression. 
8. Develop a program to calculate nPr and nCr given n and r. 
9. Write a function to get the transpose of a matrix. 
10. Write a C program with two functions itob (n, s) and itoh (n, s). itob converts integer into
binary character representation in s. Similarly itoh converts integer into hexadecimal
character representation in s. 
11. Write a C program with a function indexr(s,t), which returns the index of rightmost
occurrence of t in s otherwise -1. 
12. Write a C program with a recursive function itoa, which converts integer into a string. 
13. Write a program to add the first seven terms of the following series: 1 / 1! + 2 / 2! –3 /3! + 4
/ 4! . . .
14. Write a program to compute factorial and GCD using recursion.
15. 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 of multiplication, division, factorials (use recursion) and squares. Modularize the
code wherever possible.

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.

Structures,Unions and Enumeration

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. 

Files ,Console I/O and Command line arguments

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

1. Write a program to count the number of bits as “1” in an 8 bit number.


2. Write a program in which define a as an unsigned integer whose value is (hexadecimal)
0xa2c3. 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. Utilize the original value of a in each expression. Assume that
a is stored in a 16-bit word
1. ~a
2. a ^ 0x3f06
3. a | 0x3f06
4. a | ~0x3f06
5. a >> 3
6. a << 5
7. a ^ ~a
8. a | ~a
9. (a & ~0x3f06) << 8
10. a & ~ (0x3f06 >> 8
3. Write a C program that will accept a hexadecimal number as input, and then display a menu
that will permit any of the following operations to be carried out
1. Display the hexadecimal equivalent of the one’s complement
2. Carry out a masking operation and then display the hexadecimal equivalent of the
result
3. Carry out a bit shifting operation and then display the hexadecimal equivalent of the
result
4. Exit

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. 

4. Write a Program to set a bit at nth position in number.


5. Write a Program to unset/clear a bit at nth position in the number.
6. Write a Program to toggle a bit at nth position in number.
7. Write a Program to check if the bit at n​th​ position in number is set or not.
8. Write a C program that will illustrate the equivalence between
● Shifting a binary number to the left n bits and multiplying the binary number by 2​n
● Shifting a binary number to the right n bits and dividing the binary number by 2​n​.

Choose the initial binary number carefully, so that bits will not be lost as a result of the
shifting operation.

Preprocessor

1. Write a C program to calculate factorial of a number. Factorial function has to be written as


a multiline macro.
2. Develop sample programs using preprocessor operators #, ## and also conditional
compilation.

You might also like