Friday 12 May 2023

Questions

 Exercise 1

Set A . Apply all the three program development steps for the following examples.

 1. Accept dimensions of a cylinder and print the surface area and volume (Hint: surface area =
2pr2 + 2prh, volume = pr2h)


2. Accept temperatures in Fahrenheit (F) and print it in Celsius(C) and Kelvin (K) (Hint: C=5/9(F-
32), K = C + 273.15)

 3. Accept initial velocity (u), acceleration (a) and time (t). Print the final velocity (v) and the
distance (s) travelled. (Hint: v = u + at, s = u + at2)

 4. Accept inner and outer radius of a ring and print the perimeter and area of the ring (Hint:
perimeter = 2 p (a+b) , area = p (a2-b2) )

 5. Accept two numbers and print arithmetic and harmonic mean of the two numbers (Hint: AM=
(a+b)/2 , HM = ab/(a+b) )

 6. Accept three dimensions length (l), breadth(b) and height(h) of a cuboid and print surface
area and volume (Hint : surface area=2(lb+lh+bh ), volume = lbh )

 7. Accept a character from the keyboard and display its previous and next character in order.
Ex. If the character entered is ‘d’, display “The previous character is c”, “The next character is e”.

 8. Accept a character from the user and display its ASCII value.

Set B . Apply all the three program development steps for the following examples.

1. Accept the x and y coordinates of two points and compute the distance between the two
points.

 2. Accept two integers from the user and interchange them. Display the interchanged numbers.

 3. A cashier has currency notes of denomination 1, 5 and 10. Accept the amount to be
withdrawn from the user and print the total number of currency notes of each denomination the
cashier will have to give.


 Set C. Write a program to solve the following problems

1. Consider a room having one door and two windows both of the same size. Accept
dimensions of the room, door and window. Print the area to be painted (interior walls) and area to
be whitewashed (roof).

 2. The basic salary of an employee is decided at the time of employment, which may be
different for different employees. Apart from basic, employee gets 10% of basic as house rent,
30% of basic as dearness allowance. A professional tax of 5% of basic is deducted from salary.
Accept the employee id and basic salary for an employee and output the take home salary of the
employee


Exercise 2

 Set A: Apply all the three program development steps for the following examples.

1. Write a program to accept an integer and check if it is even or odd.

 2. Write a program to accept three numbers and check whether the first is between the other
two numbers. Ex: Input 20 10 30. Output: 20 is between 10 and 30

 3. Accept a character as input and check whether the character is a digit. (Check if it is in the
range ‘0’ to ‘9’ both inclusive)

 4. Write a program to accept a number and check if it is divisible by 5 and 7.

 5. Write a program, which accepts annual basic salary of an employee and calculates and
displays the Income tax as per the following rules.
Basic: < 1,50,000 Tax = 0
1,50,000 to 3,00,000 Tax = 20%
> 3,00,000 Tax = 30%

 6. Accept a lowercase character from the user and check whether the character is a vowel or
consonant. (Hint: a,e,i,o,u are vowels)


Set B: Apply all the three program development steps for the following examples.

1. Write a program to check whether given character is a digit or a character in lowercase or
uppercase alphabet. (Hint ASCII value of digit is between 48 to 58 and Lowercase characters
have ASCII values in the range of 97 to122, uppercase is between 65 and 90)

 2. Accept the time as hour, minute and seconds and check whether the time is valid. (Hint:
0<=hour<24, 0<=minute <60, 0<=second <60)

 3. Accept any year as input through the keyboard. Write a program to check whether the year is
a leap year or not. (Hint leap year is divisible by 4 and not by 100 or divisible by 400)

 4. Accept three sides of triangle as input, and print whether the triangle is valid or not. (Hint:
The triangle is valid if the sum of each of the two sides is greater than the third side).

 5. Accept the x and y coordinate of a point and find the quadrant in which the point lies.

 6. Write a program to calculate the roots of a quadratic equation. Consider all possible cases.

 7. Accept the cost price and selling price from the keyboard. Find out if the seller has made a
profit or loss and display how much profit or loss has been made.


Set C: Write programs to solve the following problems

 1. Write a program to accept marks for three subjects and find the total marks secured ,
average and also display the class obtained. (Class I – above __%, class II – ___% to ___%,
pass class – ___% to ___% and fail otherwise)

 2. Write a program to accept quantity and rate for three items, compute the total sales amount,
Also compute and print the discount as follows: (amount > ____– 20% discount, amount between
___ to _____ -- 15% discount, amount between – ____ to ____ -- 8 % discount)

 3. A library charges a fine for every book returned late. Accept the number of days the member
is late, compute and print the fine as follows:(less than five days Rs ___ fine, for 6 to 10 days Rs.
____ fine and above 10 days Rs. ___ fine )

Exercise 3

Set A: Apply all the three program development steps for the following examples.
 1. Accept a single digit from the user and display it in words. For example, if digit entered is 9,
display Nine.
 

 2. Write a program, which accepts two integers and an operator as a character (+ - * /),
performs the corresponding operation and displays the result.

 3. Accept two numbers in variables x and y from the user and perform the following operations
Options Actions
1. Equality Check if x is equal to y
2. Less Than Check if x is less than y
3. Quotient and Remainder Divide x by y and display the quotient and remainder
 

4. Range Accept a number and check if it lies between x and y
(both inclusive)
 

5. Swap Interchange x and y

Set B: Apply all the three program development steps for the following examples.
 

1. Accept radius from the user and write a program having menu with the following options and
corresponding actions
Options Actions
1. Area of Circle Compute area of circle and print
2. Circumference of Circle Compute Circumference of circle and print
3. Volume of Sphere Compute Volume of Sphere and print

 2. Write a program having a menu with the following options and corresponding actions
Options Actions
1. Area of square Accept length ,Compute area of square and print
2. Area of Rectangle Accept length and breadth, Compute area of rectangle
and print
3. Area of triangle Accept base and height , Compute area of triangle and
print


Set C: Write a program to solve the following problems

1. Accept the three positive integers for date from the user (day, month and year) and check
whether the date is valid or invalid. Run your program for the following dates and fill the table.
(Hint: For valid date 1<=month<=12,1<= day <=no-of-days where no-of-days is 30 in case of
months 4, 6,9 and 11. 31 in case of months 1,3,5,7,8,10 and 12. In case of month 2 no-of-days is
28 or 29 depending on year is leap or not)
Date Output
12-10-1984
32-10-1920
10-13-1984
29-2-1984
29-2-2003
29-2-1900
__________

 2. Write a program having menu that has three options - add, subtract or multiply two fractions.
The two fractions and the options are taken as input and the result is displayed as output. Each
fraction is read as two integers, numerator and denominator.


 Exercise 4  

Set A . Apply all the three program development steps for the following examples.

1. Write a program to accept an integer n and display all even numbers upto n.

 2. Accept two integers x and y and calculate the sum of all integers between x and y (both
inclusive)

 3. Write a program to accept two integers x and n and compute xn

 4. Write a program to accept an integer and check if it is prime or not.

 5. Write a program to accept an integer and count the number of digits in the number.

 6. Write a program to accept an integer and reverse the number. Example: Input: 546, Output
645.

 7. Write a program to accept a character, an integer n and display the next n characters.

Set B. Apply all the three program development steps for the following examples.
 

 1. Write a program to display the first n Fibonacci numbers. (1 1 2 3 5 ……)

 2. Write a program to accept real number x and integer n and calculate the sum of first n terms
of the series x+ 3x+5x+7x+…

 3. Write a program to accept real number x and integer n and calculate the sum of first n terms
of the series
x1+ 22x+ 33x+ ……

 4. Write a program to accept characters till the user enters EOF and count number of alphabets
and digits entered. Refer to sample program 5 given above.

 5. Write a program, which accepts a number n and displays each digit in words. Example: 6702
Output = Six-Seven-Zero-Two. (Hint: Reverse the number and use a switch statement)


Set C. Write C programs to solve the following problems

 1. Write a program to accept characters from the user till the user enters * and count the
number of characters, words and lines entered by the user. (Hint: Use a flag to count words.
Consider delimiters like \n \t , ; . and space for counting words)

 2. Write a program which accepts a number and checks if the number is a palindrome (Hint
number = reverse of number)
Example: number = 3472 Output: It is not a palindrome
number = 262, Output : It is a palindrome

 3. A train leaves station A at 4.00 a.m and travels at 80kmph. After every 30 minutes, it reaches
a station where it halts for 10 minutes. It reaches its final destination B at 1.00 p.m. Display a
table showing its arrival and departure time at every intermediate station. Also calculate the total
distance between A and B. 


4. A task takes 4 ½ hours to complete. Two workers, A and B start working on it and take turns
alternately. A works for 25 minutes at a time and is paid Rs 50, B works for 75 minutes at a time
and is paid Rs. 150. Display the total number of turns taken by A and B, calculate their total
amounts and also the total cost of the task.

Exercise 5

Set A . Write C programs for the following problems.

 1. Write a program to display all prime numbers between ____ and ____.

 2. Write a program to display multiplication tables from ___ to ___ having n multiples each. The
output should be displayed in a tabular format. For example, the multiplication tables of 2 to 9
having 10 multiples each is shown below.
2 ´ 1 = 2 3 ´ 1 = 3 ………….9 ´ 1 = 9
2 ´ 2 = 4 3 ´ 2 = 6…………..9 ´ 2 = 18
…………. ………….
2 ´ 10 = 20 3 ´ 10 = 30………..9 ´ 10 = 90

 3. Modify the sample program 1 to display n lines as follows (here n=4).
     A B C D
     E F G
    H I
     J 


Set B. Write C programs for the following problems.

 1. Write a program to display all Armstrong numbers between 1 and 500. (An Armstrong
number is a number such that the sum of cube of digits = number itself Ex. 153 = 1*1*1 + 5*5*5
+ 3*3*3
2. Accept characters till the user enters EOF and count the number of lines entered. Also
display the length of the longest line. (Hint: A line ends when the character is \n)
 3. Display all perfect numbers below 500. [A perfect number is a number, such that the sum of
its factors is equal to the number itself]. Example: 6 (1 + 2 + 3), 28 (1+2+4+7+14)


Set C. Write C programs to solve the following problems
1. A company has four branches, one in each zone: North, South, East and West. For each of
these branches, it collects sales information once every quarter (four months) and calculates the
average sales for each zone. Write a program that accepts sales details for each quarter in the
four branches and calculate the average sales of each branch.
2. A polynomial in one variable is of the form a0 + a1x + a2x2 + …. For example, 6 - 9x + 2x5.
Write a program to calculate the value of a polynomial. Accept the number of terms n , the value
of x, and n+1coefficients.
 3. The temperature of a city varies according to seasons. There are four seasons – spring,
summer, Monsoon and winter. The temperature ranges are: Spring (15-25 degrees), Summer
(25-40 degrees), Monsoon (20-35 degrees), Winter (5-20 degrees). Accept weekly temperatures
(12 weeks per season) for each season, check if they are in the correct range and calculate the
average temperature for each season. 


Exercise 6

Set A . Write C programs for the following problems

1. Write a program, which accepts a character from the user and checks if it is an alphabet, digit
or punctuation symbol. If it is an alphabet, check if it is uppercase or lowercase and then change
the case.


2. Write a menu driven program to perform the following operations till the user selects Exit.
Accept appropriate data for each option. Use standard library functions from math.h
i. Sine ii. Cosine iii. log iv. ex v. Square Root vi. Exit
 

3. Accept two complex numbers from the user (real part, imaginary part). Write a menu driven
program to perform the following operations till the user selects Exit.
i. ADD ii. SUBTRACT iii. MULTIPLY iv. EXIT 


Set B . Write C programs for the following problems
 
 1. Accept x and y coordinates of two points and write a menu driven program to perform the
following operations till the user selects Exit.
i. Distance between points.
ii. Slope of line between the points.
iii. Check whether they lie in the same quadrant.
iv. EXIT
(Hint: Use formula m = (y2-y1)/(x2-x1) to calculate slope of line.)

 2. Write a simple menu driven program for a shop, which sells the following items:
The user selects items using a menu. For every item selected, ask the quantity. If the quantity of
any item is more than 10, give a discount of _____%. When the user selects Exit, display the
total amount.


Set C . Write C programs for the following problems
 
 1. Write a program to calculate the total price for a picnic lunch that a user is purchasing for her
group of friends. She is first asked to enter a budget for the lunch. She has the option of buying
apples, cake, and bread. Set the price per kg of apples, price per cake, and price per loaf of bread
in constant variables. Use a menu to ask the user what item and how much of each item she
would like to purchase. Keep calculating the total of the items purchased. After purchase of an
item, display the remaining amount. Exit the menu if the total has exceeded the budget. In
addition, provide an option that allows the user to exit the purchasing loop at any time. 


Exercise 7

Set A . Write C programs for the following problems


1. Write a function isEven, which accepts an integer as parameter and returns 1 if the number is
even, and 0 otherwise. Use this function in main to accept n numbers and ckeck if they are even
or odd.

2. Write a function, which accepts a character and integer n as parameter and displays the next
n characters.

3. Write a function, which accepts a character and integer n as parameter and displays the next
n characters.

Set B . Write C programs for the following problems


1. Write a function isPrime, which accepts an integer as parameter and returns 1 if the number
is prime and 0 otherwise. Use this function in main to display the first 10 prime numbers.

2. Write a function that accepts a character as parameter and returns 1 if it is an alphabet, 2 if it
is a digit and 3 if it is a special symbol. In main, accept characters till the user enters EOF and use
the function to count the total number of alphabets, digits and special symbols entered.

3. Write a function power, which calculates xy. Write another function, which calculates n! Using
for loop. Use these functions to calculate the sum of first n terms of the Taylor series:
sin(x) = x -
3!
x3+5!x5+ ……

Set C . Write C programs for the following problems

1. Write a menu driven program to perform the following operations using the Taylor series.
Accept suitable data for each option. Write separate functions for each option.
i. ex
ii. sin(x)
iii. cos (x)

Exercise 8

Set A . Write C programs for the following problems

1. Write a recursive C function to calculate the sum of digits of a number. Use this function in
main to accept a number and print sum of its digits.

 2. Write a recursive C function to calculate the GCD of two numbers. Use this function in main.
The GCD is calculated as :
gcd(a,b) = a if b = 0
= gcd (b, a mod b) otherwise

 3. Write a recursive function for the following recursive definition. Use this function in main to
display the first 10 numbers of the following series
an = 3 if n = 1 or 2
= 2* an-1 + 3*an-2 if n > 2


 4. Write a recursive C function to calculate xy. (Do not use standard library function)

Set B . Write C programs for the following problems

 1. Write a recursive function to calculate the nth Fibonacci number. Use this function in main to
display the first n Fibonacci numbers. The recursive definition of nth Fibonacci number is as
follows:
fib(n) = 1 if n = 1 or 2= fib(n-2) + fib(n-1) if n>2

2. Write a recursive function to calculate the sum of digits of a number till you get a single digit
number. Example: 961 -> 16 -> 5. (Note: Do not use a loop)

 3. Write a recursive C function to print the digits of a number in reverse order. Use this function
in main to accept a number and print the digits in reverse order separated by tab.
Example 3456
6 5 4 3
(Hint: Recursiveprint(n) = print n if n is single digit number= print n % 10 + tab + Recursiveprint( n/10)


Set C . Write C programs for the following problems

1. The “Towers of Hanoi” problem: The objective is to move a set of disks arranged in
increasing sizes from top to bottom from the source pole to a destination pole such that they are
in the same order as before using only one intermediate pole subject to the condition that
· Only one disk can be moved at a time
· A bigger disk cannot be placed on a smaller disk.
Write a recursive function which displays all the steps to move n disks from A to C.


Exercise 9

Set A. Write programs to solve the following problems

1. Write a program to accept n numbers in the range of 1 to 25 and count the frequency of
occurrence of each number.

 2. Write a function for Linear Search, which accepts an array of n elements and a key as
parameters and returns the position of key in the array and -1 if the key is not found. Accept n
numbers from the user, store them in an array. Accept the key to be searched and search it using
this function. Display appropriate messages.

 3. Write a function, which accepts an integer array and an integer as parameters and counts
the occurrences of the number in the array.

 4. Write a program to accept n numbers and store all prime numbers in an array called prime.
Display this array. 


Set B. Write programs to solve the following problems
 
1. Write a program to accept n numbers from the user and store them in an array such that the
elements are in the sorted order. Display the array. Write separate functions to accept and display
the array. (Hint: Insert every number in its correct position in the array)

 2. Write a function to sort an array of n integers using Bubble sort method. Accept n numbers
from the user, store them in an array and sort them using this function. Display the sorted array.

 3. Write a program to accept a decimal number and convert it to binary, octal and hexadecimal.
Write separate functions.

 4. Write a program to find the union and intersection of the two sets of integers (store it in two
arrays).

 5. Write a program to remove all duplicate elements from an array.

Set C. Write programs to solve the following problems
 

1. Write a program to merge two sorted arrays into a third array such that the third array is also
in the sorted order.
a1 10 25 90
a2 9 16 22 26 10
0
a3 9 10 16 22 25 26 90 100
€ 2. Write a program to accept characters from the user till the user enters EOF and calculate the
frequency count of every alphabet. Display the alphabets and their count.
Input: THIS IS A SAMPLE INPUT
Output: Character Count
T 2
H 1
I 3
…….
 3. Write a recursive function for Binary Search, which accepts an array of n elements and a key
as parameters and returns the position of key in the array and -1 if the key is not found. Accept n
numbers from the user, store them in an array and sort the array. Accept the key to be searched
and search it using this function. Display appropriate messages


Exercise 10

Set A . Write C programs for the following problems.

1. Write a program to accept a matrix A of size mXn and store its transpose in matrix B. Display
matrix B. Write separate functions.

 2. Write a program to add and multiply two matrices. Write separate functions to accept,
display, add and multiply the matrices. Perform necessary checks before adding and multiplying
the matrices


 Set B . Write C programs for the following problems.

1. Write a menu driven program to perform the following operations on a square matrix. Write
separate functions for each option.
i) Check if the matrix is symmetric.
ii) Display the trace of the matrix (sum of diagonal elements).
iii) Check if the matrix is an upper triangular matrix.

 2. Write a menu driven program to perform the following operations on a square matrix. Write
separate functions for each option.
i) Check if the matrix is a lower triangular matrix.
ii) Check if it is an identity matrix.

 3. Write a program to accept an mXn matrix and display an m+1 X n+1 matrix such that the
m+1th row contains the sum of all elements of corresponding row and the n+1th column contains
the sum of elements of the corresponding column.
Example:
A B
1 2 3 1 2 3 6
4 5 6 4 5 6 15
7 8 9 7 8 9 24
12 15 18 45


Set C. Write programs to solve the following problems

1. Pascal's triangle is a geometric arrangement of the binomial coefficients in a triangle. It is
named after Blaise Pascal. Write a program to display n lines of the triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1

2. A magic square of order n is an arrangement of n² numbers, in a square, such that the n
numbers in all rows, all columns, and both diagonals sum to the same constant. A normal magic
square contains the integers from 1 to n². The magic constant of a magic square depends on n
and is M(n) = (n3+n)/2. For n=3,4,5, the constants are 15, 34, 65 resp. Write a program to
generate and display a magic square of order n.

Exercise 11

Set A . Write C programs for the following problems.

 1. Write a function which takes hours, minutes and seconds as parameters and an integer s
and increments the time by s seconds. Accept time and seconds in main and Display the new
time in main using the above function.

 2. Write a program to display the elements of an array containing n integers in the reverse
order using a pointer to the array.

 3. Write a program to allocate memory dynamically for n integers such that the memory is
initialized to 0. Accept the data from the user and find the range of the data elements.


Set B . Write C programs for the following problems.

 1. Accept n integers in array A. Pass this array and two counter variables to a function which
will set the first counter to the total number of even values in the array and the other to the total
number of odd values. Display these counts in main. (Hint: Pass the addresses of the counters to
the function)

2. Write a function which accepts a number and three flags as parameters. If the number is
even, set the first flag to 1. If the number is prime, set the second flag to 1. If the number is
divisible by 3 or 7, set the third flag to 1. In main, accept an integer and use this function to check
if it is even, prime and divisible by 3 or 7. (Hint : pass the addresses of flags to the function)

Set C. Write programs to solve the following problems

 1. Accept the number of rows (m) and columns (n) for a matrix and dynamically allocate
memory for the matrix. Accept and display the matrix using pointers. Hint: Use an array of
pointers.
 

 2. There are 5 students numbered 1 to 5. Each student appears for different number of
subjects in an exam. Accept the number of subjects for each student and then accept the marks
for each subject. For each student, calculate the percentage and display. (Hint: Use array of 5
pointers and use dynamic memory allocation)


Exercise 12

Set A . Write C programs for the following problems.

 1. Write a menu driven program to perform the following operations on strings using standard
library functions:
Length € Copy € Concatenation € Compare
Reverse € Uppercase € Lowercase € Check case

 2. Write a program that will accept a string and character to search. The program will
call a function, which will search for the occurrence position of the character in the

string and return its position. Function should return –1 if the character is not found in
the string.

 3. A palindrome is a string that reads the same-forward and reverse. Example: “madam” is a
Palindrome. Write a function which accepts a string and returns 1 if the string is a palindrome and
0 otherwise. Use this function in main.

 4. For the following standard functions, write corresponding user defined functions and write a
menu driven program to use them. strcat, strcmp, strrev, strupr

 5. Write a program which accepts a sentence from the user and alters it as follows:
Every space is replaced by *, case of all alphabets is reversed, digits are replaced by ?

Set B . Write C programs for the following problems

1. Write a menu driven program which performs the following operations on strings. Write a
separate function for each option. Use pointers
i. Check if one string is a substring of another.
ii. Count number of occurrences of a character in the string.
iii. Replace all occurrences of a character by another.

 2. Write a program in C to reverse each word in a sentence.

 3. Write a function which displays a string in the reverse order. (Use recursion)

Set C. Write programs to solve the following problems

 1. Write a program that accepts a sentence and returns the sentence with all the extra
spaces trimmed off. (In a sentence, words need to be separated by only one space; if
any two words are separated by more than one space, remove extra spaces)

 2. Write a program that accepts a string and displays it in the shape of a kite. Example: “abcd”
will be displayed as :
                      aa
                    abab
                  abcabc
                abcdabcd
                  abcabc
                    abab
                      aa

 3. Write a program that accepts a string and generates all its permutations. For example: ABC,
ACB, BAC, BCA, CAB, CBA

 4. Write a program to display a histogram of the frequencies of different characters in a
sentence. Note: The histogram can be displayed as horizontal bars constructed using * character.
Example: this is a single string


h    *
t    * 
i    *  *  *  *
h   *  *  *  *
s    *  *

a    *  *
n    *  *
g    *
l      *
e     *

r     *

Exercise 13

Set A . Write C programs for the following problems.

 1. Write a program that accepts n words and outputs them in dictionary order.

 2. Write a program that accepts n strings and displays the longest string.

 3. Write a program that accepts a sentence and splits the sentence into words. Sort each word
and reconstruct the sentence.
Input – this is a string Output – hist is a ginrst


Set B . Write C programs for the following problems.

1. Write a function, which displays a given number in words.
For Example: 129 One Hundred Twenty Nine
2019 Two Thousand Nineteen

 2. Define two constant arrays of strings, one containing country names (ex: India, France etc)
and the other containing their capitals. (ex: Delhi, Paris etc). Note that country names and capital
names have a one-one correspondence. Accept a country name from the user and display its
capital. Example: Input: India , Output: Delhi.


Set C. Write programs to solve the following problems

1. Create a mini dictionary of your own. Each entry in the dictionary contains three parts (word,
its meaning, similar word). The entries are stored in the sorted order of words. Write a menu
driven program, which performs the following operations.
i. Add a new word (Insert new word and its details in the correct position)
ii. Dictionary look-up
iii. Find similar word
iv. Delete word
v. Display All words starting with a specific alphabet (along with their meaning).
(Hint: Use 2-D array of strings having n rows and 3 columns)


Exercise 14

Set A . Write C programs for the following problems.

1. Write a program to accept 2 integers and perform bitwise AND, OR, XOR and Complement.
Display the inputs and results in binary format. Use the function in the above exercise.


 2. Write a program to swap two variables without using a temporary variable. (Hint: Use XOR)

 3. Write a program which accepts two integers x and y and performs x<<y and x>>y. Display
the result in binary

Set B . Write C programs for the following problems.

 1. Write functions to calculate the size of an integer, character, long and short integer using
bitwise operators. Store their declaration in file “myfunctions.h” and their definitions in file
“myfunctions.c”. Include these files in your program and use these functions to display the size of
each.

 2. Write a program to perform the following operations on an unsigned integer using bitwise
operators and display the result in hexadecimal format.
i. Swap the ____ and ____ nibble ( 4 bits)
ii. Remove the lower order nibbles from the number.
For example: Input: A3F1 Output 00A3
iii. Reverse the nibbles
For example: Input: A3F1 Output 1F3A

 3. Write a program which accepts an integer and checks whether it is a power of 2.

Set C. Write programs to solve the following problems

 1. Write a program to add, subtract, multiply and divide two integers using bitwise operators.

 2. Packing and Unpacking Data: A date consists of three parts : day, month, year. To store this
information, we would require 3 integers. However, day and month can take only limited values.
Hence, we can store all three in a single integer variable by packing bits together. If we are using
the dd-mm-yy format, the date will be stored in memory as an unsigned integer (16 bits) in the
following format. Year (Bits 15-9), Month (bits 8 – 5), Day (Bits 4 - 0).
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
y y y y y y y m m m m d d d d d
hour Month day
Accept day, month and year from the user and pack them into a single unsigned int. Unpack and
display them in the binary format. (Hint: for packing, use: 512 * year + 32 * month + day )
The output should be:
Enter the date, month and year –dd mm yy :
31 12 89
Packed date = 1011001110011111
Day = 31
0000000000011111
Month = 12
0000000000001100
Year = 89
0000000001011001

 3. Packing and Unpacking Data: Time consists of three parts : hours, minutes, seconds. To
store this information, we would require 3 integers. However, all these three variable take only
limited values. Hence, we can store all three in a single integer variable by packing bits together.
Time being 0 to 23 hours, it will require maximum 5 bits, minutes being 0 to 59 will require 6 bits.
The two together take up 11 bits. The remaining 5 bits cannot store seconds which are also in the
range 0 to 59 hence we store double seconds which are in the range 0 to 29
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
h h h h h m m m m m m ds ds ds ds ds
hour Minutes Double seconds
Accept hour, minute and double seconds from the user and pack them into a single unsigned int.
Unpack and display them in the binary format.
The output should be:
Enter the hour, minutes and double seconds –hh mm ss :
07 12 20
Packed date = 0011100110010100
Hour = 07
0000000000000111
Minutes = 12
0000000000001100
Double seconds = 20
0000000000010100
Signature of the


Exercise 15

Set A . Write C programs for the following problems.

 1. Create a structure student (roll number, name, marks of 3 subjects, percentage). Accept
details of n students and write a menu driven program to perform the following operations. Write
separate functions for the different options.
i) Search
ii) Modify
iii) Display all student details
iv) Display all student having percentage > _____
v) Display student having maximum percentage

2. Create a structure employee (id, name, salary). Accept details of n employees and write a
menu driven program to perform the following operations. Write separate functions for the
different options.
i) Search by name
ii) Search by id
iii) Display all
iv) Display all employees having salary > _____
v) Display employee having maximum salary
Instructor should fill in the blanks with appropriate values.
Signature of the instructor Date

Set B . Write C programs for the following problems.

 1. Create a structure having the following fields:
Structure name: _______
Fields: ________, _______, _______, ________, _______, _______
Accept details of n variables of the above structure and write a menu driven program to perform
the following operations. Write separate functions for the different options.
i) ______ ii) _________ iii) __________ iv) __________

 2. Create a structure Fraction (numerator, denominator). Accept details of n fractions and write
a menu driven program to perform the following operations. Write separate functions for the
different options. Use dynamic memory allocation. Note: While accepting fractions, store the
fractions in the reduced form.
i) Display the largest fraction
ii) Display the smallest fraction
iii) Sort fractions
iv) Display all

Set C. Write programs to solve the following problems

 1. Accept book details of ‘n’ books viz, book title, author, publisher and cost. Assign an
accession numbers to each book in increasing order. (Use dynamic memory allocation).
Write a menu driven program for the following options.
i. Books of a specific author
ii. Books by a specific publisher
iii. All books having cost >= _____ .
iv. Information about a particular book (accept the title)
v. All books.

 2. The government of a state wants to collect census information for each city and store the
following information : city name, population of the city, literacy percentage. After collecting data
for all cities in the state, the government wants to view the data according to :
i. Literacy level
ii. Population
iii. Details of a specific city.
Write a C program using structures and dynamic memory allocation

Exercise 16      

Set A . Write C programs for the following problems.

 1. Modify the sample program 1 above to accept details for n books and write a menu driven
program for the following:
 i) Display all text books
 ii) Search Text Book according to Title
iii) Find the total cost of all books (Hint: Use no_of_copies).

 2. Modify the sample program 1 to accept details for n books and write a menu driven program
for the following:
 i) Display all magazines
 ii) Display magazine details for specific month.
iii) Find the “costliest” magazine.

 3. Modify the sample program 1 to accept details for n books and write a menu driven program
for the following:
 i) Display all reference books
 ii) Find the total number of reference books
 iii) Display the edition of a specific reference book.

Set B. Write programs to solve the following problems

1. Create a structure named ________having the following fields:
Field name Description
Write a menu driven program to perform the following operations :
i) _________ ii) _________ iii) _________ iv) _________ v) _________

 2. Write a program to create a linked list of n nodes and accept data from the user for each
node. Display the list. Accept a number from the user and search for the element in the list.

Set C. Write programs to solve the following problems

 1. A shop sells electronic items. Each item has an id, company name, code (1-TV, 2-Mobile
phones, 3-Camera) and cost. The following additional details are stored for each item.
· TV - size, type ( CRT-1 / LCD- 2 / Plasma-3)
· Mobile Phone - type ( GSM – 1 / CDMA – 2) , model number.
· Camera – resolution, model number.
The shop wants to maintain a list of all items and perform the following operations for each of the
item types:
i) Display all
ii) Search for specific item
iii) Sort according to cost

 2. Write a program to create a linked list of n nodes and accept data from the user for each
node. Write a menu driven program to perform the following operations:
i) Display the list
ii) Search for specific number
iii) Display the element after ____
iv) Find the maximum / minimum

Exe17

Set A . Write C programs for the following problems.

 1. Write a program to accept three integers as command line arguments and find the minimum,
maximum and average of the three. Display error message if invalid number of arguments are
entered.

 2. Write a program which accepts a string and two characters as command line arguments and
replace all occurrences of the first character by the second.

3. Define a macro EQUALINT which compares two parameters x and y and gives 1 if equal
and 0 otherwise. Use this macro to accept pairs of integers from the user. Calculate the sum of
digits of both and continue till the user enters a pair whose sum of digits is not equal.

 4. Define a macro EQUALSTR which compares two strings x and y and gives 1 if equal and 0
otherwise. Use this macro to accept two strings from the user and check if they are equal.

Set B . Write C programs for the following problems.

 1. Write a program to accept two strings as command line arguments and display the union
and intersection of the strings. If the user enters invalid number of arguments, display appropriate
message.

 2. Write a program which accepts a string and an integer (0 or 1) as command line arguments.
If the integer entered is 0, sort the string alphabetically in the ascending order and if it is 1, sort it
in the descending order. If the user enters invalid number of arguments, display appropriate
message. (Hint – use atoi)

Set C . Write C programs for the following problems.

1. Create a header file “mymacros.h” which defines the following macros.
i. SQR(x) ii. CUBE(x) - nested iii. GREATER2(x,y) iv. GREATER3 (x,y,z) – nested
v. FLAG ( value = 1) (which may or may not be defined)
Include this file in your program. Write a menu driven program to use macros SQR, CUBE,
GREATER2 and GREATER3. Your program should run the first two macros if the macro called
FLAG has been defined. If it is not defined, execute the other two macros. Run the program twice
– with FLAG defined and with FLAG not defined.

EXE18

Set A . Write C programs for the following problems.

 1. Write a program to accept two filenames as command line arguments. Copy the contents of
the first file to the second such that the case of all alphabets is reversed.

 2. Write a program to accept a filename as command line argument and count the number of
words, lines and characters in the file.

 3. Write a program to accept details of n students (roll number, name, percentage) and write it
to a file named “student.txt”. Accept roll number from the user and search the student in the file.
Also display the student details having the highest percentage.

Set B. Write programs to solve the following problems

 1. A file named numbers.txt has a set of integers. Write a C program to read this file and
convert the integers into words and write the integer and the words in another file named
numwords.txt.
Example:
numbers.txt numwords.txt
11 Eleven
261 Two hundred Sixty One
9 Nine

 2. Write a program which accepts a filename and an integer as command line arguments and
encrypts the file using the key. (Use any encryption algorithm)

Set C . Write C programs for the following problems.

1. A text file contains lines of text. Write a program which removes all extra spaces from the
file.

 2. Write a menu driven program for a simple text editor to perform the following operations on a
file, which contains lines of text.
i. Display the file
ii. Copy m lines from position n to p
iii. Delete m lines from position p
iv. Modify the nth line
v. Add n lines

 3. Write a program which reads the contents of a C program and replaces all macros occurring
in the program with its value. Assume only simple substitution macros (ex: #define FALSE 0 ).

EXE19

Set A . Write C programs for the following problems.

1. Create a structure student (roll number, name, percentage) Write a menu driven program to
perform the following operations on a binary file- “student.dat”. Write separate functions for the
different options.
1. Add a student (Note: Students should be assigned roll numbers consecutively)
2. Search Student
a. according to name
b. according to roll number
3. Display all students

 2. Create a structure student (roll number, name, percentage) Write a menu driven program to
perform the following operations on a binary file- “student.dat”. Write separate functions for the
different options.
1. Add a student (Note: Students will be assigned roll numbers consecutively)
2. Modify details
a. according to name
b. according to roll number
3. Display all students

 3. Create a structure student (roll number, name, percentage). Write a menu driven program to
perform the following operations on a binary file- “student.dat”. Write separate functions for the
different options.
1. Add a student (Note: Students will be assigned roll numbers consecutively)
2. Delete student
a. according to name
b. according to roll number
3. Display all students

Set B . Write C programs for the following problems.

1. Create two binary files such that they contain roll numbers, names and percentages. The
percentages are in ascending orders. Merge these two into the third file such that the third file still
remains sorted on percentage. Accept the three filenames as command line arguments.

2. Create a structure having the following fields:
Structure name: _______
Fields: __________________________________________________________________
Store information for n variables of the above structure in a binary file. Write a menu driven
program to perform the following operations Write separate functions for the different options.
i) ______ ii) _________ iii) __________ iv) __________

Set C . Write C programs for the following problems.

1. Create a binary file which contains details of student projects namely roll number, project
name, project guide. The first line of the file contains an integer indicating the total number of
students. When the program starts, read all these details into an array and perform the following
menu driven operations. When the user selects Exit from the menu, store these details back into
the file.
1. Add 2. Delete 3. Search 2. Modify 3. Display all 4. Exit


No comments:

Post a Comment

Questions

  Exercise 1 Set A . Apply all the three program development steps for the following examples.  1. Accept dimensions of a cylinder and p...