Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Data Structure Lab Assignment-2

INSTRUCTIONS
Write comment to make your programs readable.
Use descriptive variables in your programs (Name of the variables should show their purposes)

(Problems Based on Decision Making)


1. If cost price and selling price of an item is input through the keyboard, write a program to determine whether
the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.

2. Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not.

3. Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered
through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180 degrees.

4. Find the absolute value of a number entered through the keyboard without using any function.

5. Given the length and breadth of a rectangle, write a program to find whether the area of the rectangle is greater
than its perimeter. For example, the area of the rectangle with length = 5 and breadth = 4 is greater than its perimeter.

6. Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points fall on one
straight line.

7. Given the coordinates (x, y) of a center of a circle and it’s radius, write a program which will determine
whether a point lies inside the circle, on the circle or outside the circle .

8. Given a point (x, y), write a program to find out if it lies on the x-axis, y-axis or at the origin, viz. (0, 0).

9. If the three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is
valid or not. The triangle is valid if the sum of two sides is greater than the largest of the three sides.

10. Any character is entered through the keyboard, write a program using if else ladder to determine whether the
character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the
range of ASCII values for various characters
1. Characters ASCII Values
2. A–Z 65 – 90
3. a–z 97 – 122
4. 0–9 48 – 57
5. special symbols 0 - 47, 58 - 64, 91 - 96, 123 – 127

11. Write a program using switch to display the remainder when a positive integer given by user is divided by 10.

12. Write a menu driven program using if else ladder for the binary arithmetics:
Addition,Subtracion,Multiplication,Division and Modulo operations based on user choice.If user choice is invalid
,program will report it.
13. Write the above program using switch.

14. Write a program to compute grade of students using if else adder. The grades are assigned as followed:
a. Marks Grade
b. marks<50 F
c. 50≤marks< 60 C
d. 60≤marks<70 B
e. 70≤marks<80 B+
f. 80≤marks<90 A
g. 90≤mars≤ 100 A+

15. Write the above program using switch statement.Your programming logic must show how the switch fall
through.

16. Write a program using switch to print the following message based on first character of a colour entered by
the user.Use default case for reporting error in input.
a. Messa
ge

Input
b. “Colo
ur is Red”

r or R
c. “Colo
ur is Black”

b or B
d. “Colo
ur is Yellow”

y or Y
e. “Colo
ur is Green”

g or G
f. “Colo
ur is Orange”
o or O
g. Your
programming logic must show how the switch fall through.

(Problems on Array)
1. Write a program using switch to print the following message based on first character of a colour entered by
the user.
2. Use default case for reporting error in input.
3. WAP to multiply two matrices of sizes m*n and n*p. Value of m,n and p will be given by the user.
4. WAP program to convert a given decimal number to its Binary,Octal and Hexadecimal equivalent.
5. WAP a menu driven program to convert Binary,Octal and Hexadecimal number entered by user to its Decimal
equivalent.
6. WAP to merge two sorted arrays A and B of numbers into a single sorted array C that contains every numbers
from arrays A and B, in ascending order.
7. WAP that fills a five-by-five matrix as follows
8. a) Upper left triangle with +1
9. b) Lower right triangle with -1
10. c) Diagonals with zero
11. WAP to merge two sorted arrays A and B of numbers into a single sorted array C that contains every numbers
from arrays A and B, in ascending order.
12. WAP to display the frequencies of different digits in a n*m 2-D array of integers using switch statement.Value
of n and m will be given by the user.
13. WAP to count the number of primes stored in a m*n 2-D array of integers.The value of m and n will be
entered by the user.
14. WAP (A) To sort each column a m*n 2-D array of integers and display it.( B) Sort each row of 2-D array of
part (A) and display it.

(Problems on Loop)
WAP for searching in a Sorted List using Binary search.
WAP for Sorting using Selecion Sort.
WAP for Sorting using Insertion Sort.
WAP for Sorting using Bubble Sort.

(Problems on Pattern Matching)


Write a program using nested loops to print the following patterns
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1

Write a program using nested loops to print the following patterns


*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
*********

Pascal's triangle is a number triangle with numbers arranged in rows such that each row has all Binomial Coefficients
of a non-negative integer which is 1 greater than its row no. First row will contain all Binomial Coefficient of 0, 2nd
row will contain all Binomial Coefficients of 1, 3rd row will contain all Binomial Coefficient of 3…and so on. An
example is shown below that display a Pascal’s triangle of 6 rows in terms of Binomial Coefficients.
0
C0
1 1
C0 C1
2 2 2
C0 C1 C2
3 3 3 3
C0 C1 C2 C3
4 4 4 4 4
C0 C1 C2 C3 C4
5 5 5 5 5 5
C0 C1 C2 C3 C4 C5
Write a program using nested loops to print the Pascal Triangle of N rows. The value of N will be entered by the user.
For example the Pascal’s Triangle for N=10 will be printed as follows.
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
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1

(Problems Based on String)

1. Write a program to count and delete all vowels from a string.


2. Write a program to delete all duplicate characters from a string.
3. Write a program to change all uppercase letters to lowercase and vice-versa.
4. Write a program to count the number of digits in a string.
5. Write a program to count the number of characters in a text.
6. Write a program using function to check if a given string is a palindrome or not
7. Write a program to reverse a given string.
8. Write a menu driven program to implement the following string functions:
9. strlen,strcpy,strcmp
10. Write a program using function to count the frequencies of different digits,whitespace characters (blank,tab, or
newline) and all other characters in a text.
11. Write a program to count the the number of characters,lines and words in a text. A word is any sequence of characters
that does not contain any whitespace characters(a blank,tab or newline).
12. Write a program using function that will read and display the longest line in a given text.
13. Write a program to display a histogram of frequencies of different letters(treat an uppercase and lowercase letter the
same ) in a given text.
14. Write a program using a function squeeze(s1,s2) that will delete all characters from string s1 which are contained in s2.
15. Write a program to replace each occurance of a given word in a string by the another word of the same length.
Input String: MNNIT students complain that MNNIT has no theatre of its own.
Word to be replaced:MNNIT
Replacing Word: IITKG
Output String:IITKG students complain that IITKG has no theatre of its own.

(Miscellaneous Problems)
WAP to display 1’s as well as 2’s complement of binary equivalent of a given decimal number.
WAP to add two n-digit unsigned binary numbers entered by the user.
Write a calculator app that takes both numbers and the operation as command line arguments, & prints the
output to the console.
The program should be run as: myprogram number1 number2 operation from the console.
e.g. myprogram 10 20 +
If the number of arguments are less or more than required, the program displays error message.
Print "Hello World" without using Semicolon.
Create a structure Student with member variables FirstName, LastName, Class,
ContactNo, RollNo.
In the program create an array of Student structure, and implement any sorting algorithm (Bubble Sort,
Selection Sort, etc.) to sort the array
a). On the basis of RollNo.
b). On the basis of FirstName
Create a calculator program with the following properties.
a). Create a header (.h) file "calculator.h". Implement Add, Subtract, Multiply & Divide as separate
functions in it. (Keep in mind that there should be no console input and output in the functions, the input
should be taken as parameters and output should be returned from the functions.)
b). Create a menu driven program asking the user for numbers and the operation.
c). Include the header file in the main.c and use the functions to perform the operations.

You might also like