Problem 1

Create a structure namely "Date" having data members as
i) day (1 to 31) ,
ii) month (jan,feb,.....dec) (string of three characters only) ,
iii) year (2020,2021)
Create another structure namely PDS_LAB_ASSIGNMENT having data members as
(i) Structure Date (details above)
(ii) topic (datatypes, arrays, functions , loops etc.) (input strings without spaces that will include only alphabets)
(iii) No of questions in each assignment
(iv) marks(floating-point) obtained in each assignment (out of 100). Input n number of assignments(array of structure PDS_LAB_ASSIGNMENT with size n) by taking value of n from user.
Calculate the following
a) Average marks obtained in all assignments.
b) Topics in which marks obtained are greater than average .c) Print date (DD.MON.YYYY) of the assignment which has the least number of questions.
d) Write a function marks_assignment that will return the index of the assignment whose topic name is provided by the user, print the marks corresponding to that topic in main function .(Hint Your can use strcmp function to compare the two strings)
e) Write a function print_data which returns the specific assignment from the array of assignments where the user provided date matches. This function should take the array of assignments, number of assignments and user specified date as input to the function. The returned assignment will be captured in the main() and print all the details of that assignment

Solution
Problem 2

Take an integer array as input from the user. Write a recursive function to find the absolute difference of the consecutive two elements in that array from beginning to end of the array.
To solve this problem, you need to write 2 functions: Function-1 computes the absolute difference between 2 numbers and return the same.
Function-2 is a recursive function which computes the successive differences between the elements of an array from beginning to end of an array. Function-2 uses the Function-1 for calculating the difference between 2 numbers, and it should take only the integer array and its size as input arguments.
Example:
Input: N=5
A[5] = {5,6,8,12,18}
Output: The absolute difference of 5 and 6 is:1
The absolute difference of 6 and 8 is:2
The absolute difference of 8 and 12 is:4
The absolute difference of 12 and 18 is:6

Solution
Problem 3

Write a C program using recursive functions to compute the binary equivalent for a given decimal fractional number.
Hint: In the first step, separate integer and decimal parts of a given decimal fractional number. For each part write a separate C recursive function. void int_to_bin(int, int[]), void frac_to_bin(int, int[]).
Consider the max size of the array is 16 for storing the binary equivalents of integer and fractional parts. While printing the binary equivalent of a given decimal fractional number in the main(), only required portion of binary digits to be displayed.
EX: Decimal Number = 13.625
Equivalent binary number = 1101.101

Solution
Problem 4

Write a C program to carry out the following:
(i) Input an array of positive integers int* input_array(int*, int*), whose size is controlled by either some maximum size or entry of a negative integer. The function should return the size of the input array.
(ii) Reverse the array using int* reverse_array(int*, int*).
(iii) Check whether the array elements are unique or duplicate int* check_unique_array(int *, int *).

Note: Use pointers for all operations.
Example:
Max size of an array = 10
Enter array elements = 23, 64, 998, 7, 23, -99
Length of the array = 5
Reversed array = 23, 7, 998, 64, 23
Array elements are not unique.

Solution
Problem 5

Write a C program to do the following using appropriate C functions:- (Use Pointers)
(i) Enter the input string without spaces char* enter_string()
(ii) Print the string void print_string(char*);
(iii) Compute number of vowels and consonants in the input string void compute_vowel_consonant(char*, int*, int*)
(iv) Print all permutations of a given string void permute_string(char*) ( Use Pointers to swap characters)

Example:
Input String = abcd
Number of vowels = 1
Number of Consonants = 3
Permutations of the string abcd = abcd abdc acbd acdb adcb adbc bacd badc bcad bcda
bdca bdac cbad cbda cabd cadb cdab cdba dbca dbac dcba dcab dacb dabc

Solution
Problem 6

Write the following C functions in the context of accessing Structure datatypes (using pointers)
(i) Function to read (input) multiple student records {int *roll_no, char *name, int *marks, int *total_marks} from keyboard.
(ii) Function to compute total marks for each student and update in the record.
(iii) Function for sorting the student records based on total marks struct student* sort_student_record(struct student*, int*)
Demonstrate the above functions by printing the original student records as well as sorted records.
Example:
Original Student Records:
Student [1] = 21 aaaaaa 93 85 78 256
Student [2] = 22 bbbbbb 73 65 68 206
Student [3] = 23 ccccccc 93 95 88 276

Sorted Student Records:

Student [1] = 22 bbbbbb 73 65 68 206
Student [2] = 21 aaaaaa 93 85 78 256
Student [3] = 23 ccccccc 93 95 88 276

Solution
Problem 7

Define a data type named _VECTOR containing the following information. dim: An integer denoting the dimension of the vector (assume maximum dimension could be 100).

field: An array of real numbers implementing the vector of dimension of size given in dim.

Write a program which reads two vectors of dimension N1 and N2, respectively, and compute their dot products, and the angle formed by them in degree. If the dimensions do not match, it prints an error message “Dimension Mismatch.”

Run your program with the following input data.

(i) N1=3
(1.5, -4.5, 2.8),
N2=3
(1.6, 0, -4.8)

(ii)N1=2
(1.5, 1.8),
N2=2
(1.8, -1.5)

(iii) N1=4
(1, 2, 3, 4),
N2=4
(1, -2, 3, -4)

(iv)N1=2
(1.5, 1.8),
N2=4
(1, -2, 3, -4)

Solution
Problem 8

Define a data type named _STUDENT, which should contain record of a student with the following information:

Roll_Number: A string of alpha-numeric characters of length 8.
Name: A string of maximum 100 characters.
Age: An integer
Gender: A character
CGPA: A real number.

Write a program to declare an array of _STUDENT data type capable of storing records of maximum 100 students.
The program should read records of N (to be read) students and print the record of a student who has the highest CGPA.
If there are ties in top positions, the program will print all the records in ascending order of their ages.
The program should be written by implementing functions named compute_top_cgpa(.), store_array_of_toppers(.), and print_array_of_students(.), respectively for (i) computing the top CGPA from an array of structures, (ii) storing information of students who are toppers in a separate array, and (iii) printing the records of an array in ascending order of ages. These functions are to be called in the main(.) function

Run your program with the following input data:
(i) N=5
16CS1001, Narendra Mishra, 18, M, 7.58
16AE3025, Asha Saxena, 19, F, 8.42
15IE1023, Akbar Khan, 20, M, 8.10
15ER2015, Kathy Lier, 19, F, 7.86
16IE1024, Imran Hossain, 18, M, 8.35


(ii) N=10
16CS1001, Narendra Mishra, 18, M, 7.58
16AE3025, Asha Saxena, 19, F, 8.42
15IE1023, Akbar Khan, 20, M, 8.10
15ER2015, John Smith, 19, M, 7.86
16IE1024, Imran Hossain, 18, M, 8.35
14CS1035, Jayashree Mandal, 21, F, 9.56
15EC2045, Shovna Sadhukhan, 20, F, 8.87
15CH2035, Rizia Akhtar, 19, F, 9.45
16CY1016, Rashid Khan, 18, M, 9.56
16CS2041, Ikaram Tukra, 19, M, 9.56

Solution
Problem 9

he choose function C(n,k) defines the number of ways k items can be chosen from a set of n items.
Mathematically, it is defined as C(n,k) = n!/(k!(n-k)!).
Recursively, it can be defined as C(n,k) = (n/k) * C(n- l,k-l). Write a recursive function that computes the above mathematical function. Make sure that you cover the base cases.

Write a program to test the above function. The program inputs n and k and outputs C(n,k). Assume that n k and both n and k are positive integers.

Solution
Problem 10

Define a structure to represent a circle in terms of coordinates of its centre (a, b) and its radius r. Assume these values to be float.

In the main program input six numbers al, b], rl, a2, b2, r2, and store them in two such structure variables.
Write a function which takes as input two such structure variables and returns 1 if the circles intersect, 0 if they touch at a point, and -1 if they do not intersect.

In the main program call this function and print if the input circles, intersect, touch at a point, or do not intersect.

Solution
Problem 11

An axis-parallel rectangle can be specified by four real numbers representing the coordinates of left-bottom and top-right corners. Define a structure to represent a rectangle using four float variables

Write a function that, upon input an axis parallel rectangle, returns the area of the rectangle.

Write a function that, upon input a valid rectangle and two real numbers x, y, returns whether the point (x, y) lies inside, on or outside the rectangle (1, 0, -1, values should be returned).
From the main program read the rectangle and point parameters, and call the functions. Print output of each function

Solution
Problem 12

Write a program to read an integer n (< 100) then read n number of o's and I's.
Store them in an integer array Assume that B stores an unsigned n bit binary number.
The most significant bit is the first number (0/1) read and the least significant bit is the last number (0/1) read.

Now write a function int bin2dec(int n, int *B) which converts the binary number to its decimal equivalent.
Call the above function from main(). Print both the binary number and its decimal equivalent.

Solution
Problem 13

Input two strings s and t from the user. Assume that the strings do not contain blank or any whitespace character.
Write a function that finds if s is a palindrome of t, i.e., whether the reverse of s is equal to t. If it is a palindrome, return 1; otherwise, return 0.

The parameters of the function contains only pointers to characters (not arrays):
int ispalindrome(char *s, char *t)

Do not use any string library functions. In the main function read two strings. Call the above function and print its output.

Solution
Problem 14

A submission in PDS Lab is represented by two parameters, an integer assignment number (an), and an integer roll number (rn). Define a structure submis to represent a submission.

Two submissions are duplicates if both their assignment numbers and roll numbers are identical.
Declare an array of the submis structure. Read an integer n (< 100). Read parameters for n submissions and store them in the array.

The array can have multiple number of duplicate elements. You have to remove the multiple occurrences of duplicate elements and store the distinct elements in a new array B.
For example, if n = 3, array A = {(1, 21), (10, 22), (1, 21)}, then array B = {(1, 21), (10, 22)}.

Solution
Problem 15

A line segment can be defined by its two endpoints
 A rectangle is said to be axis-parallel if its sides are parallel to the x and y-axis
 An axis parallel rectangle can be fully defined by two points – its top left corner point and bottom right corner point• Define a C structure called line to store a line segments
– i.e., store the x-y coordinates of its two endpoints
• Define a C structure named rectangle to store
an axis-parallel rectangle
– i.e. store the x-y coordinates of its top left and bottom right corners
• Write a function
 int Intersects(struct rectangle R, struct line L)
 that takes an axis parallel rectangle R and a line segment L parallel to x or y axis, and find the number of points in which L cuts R
• Write a main function to do the following:
– Define a variable of type struct rectangle
– Define a variable of type struct line
– Read in the x-y coordinates of the two corners of the rectangle
– Read in the x-y coordinates of the two endpoints of the line segment
– Call Intersects( ) to find the number of intersections between the rectangle and the line segmentS
– Print the number of intersections

Solution
Problem 16

A string X of length n is said to be a prefix of a string Y of length m if m ≥ n and if the first n characters of y are the same as the characters of X. For example, the string “khar” is a prefix of the string “kharagpur” and the string “sun” is a prefix of the string “sun”. Write a recursive C function
int IsPrefix(char X[ ], int l1, int h1, char Y[ ], int l2, int h2) that returns 1 if the substring between index l1 and index h1 of X is a prefix of the substring between index l2 and h2 of Y. The function returns 0 otherwise.

For ex, if X = “screaming” and Y = “dreaming”, then IsPrefix(X, 2, 5, Y, 1, 6) will check if the substring “ream” in X (X[2] to X[5]) is a prefix of the substring “reamin” in Y (Y[1] to Y[6]) Write a main function that
 reads in two strings in two character arrays A and B using the %s option in scanf. You can assume that the strings will have at most 100 characters.
 finds the length of the two strings.
 calls the IsPrefix() function to find if the string in A is a prefix of the string in B, and print a message appropriately.
 If the length of A is p1, and the length of B is p2, you will call IsPrefix() with the parameters (A, 0, p1 – 1, B, 0, p2 – 1).
 All printings must be done from main, there should not be anything printed inside the function.

 Hint:
 First think of two complete strings and a recursive formulation to define when is one a prefix of another
 So if X =“khar”, and Y = “kharagpur”, for X to be a prefix of Y, note that first letter of both has to be same (‘k’) and the remaining part of X (“har”) has to be a prefix of the remaining part of Y (“haragpur”). Do you see the recursion now?
 Then just use the same idea, but on the substrings defined by the parameters
 Decide what parameters to pass in the recursive call
 Work with the above example to understand
 For recursive calls made, store the return value in a variable. Then think what to do with it

Solution
Problem 17

Consider an array A of integers. You have to write a C program to find the two numbers in A with the smallest absolute difference among all such pairs of number in A.
For example, if A = 2, 5, 0, 7, 3, then the two required numbers are 2 and 3 (with absolute difference = 1, which is smaller than the absolute difference of any other pair of numbers that you can choose in A).

 Write a C function int FindDiff(int *X, int n, int *x1, int *x2) that takes as parameters an integer array X with n elements, and does the following:
 Returns the minimum absolute difference between any pair of numbers in X
 Returns the two numbers with this minimum difference using x1 and x2
 If there are more than one such pair of numbers, you
can return any one Write a main function that does the following:  Read in an integer n
 Dynamically allocate an integer array of size n using malloc()
 Read in n integers in the array A
 Call FindDiff() to find the minimum absolute difference
 Print the difference, and the corresponding two numbers, with an appropriate message

 If the array is 30, 10, 5, 20, 45, then your program should print
The minimum absolute difference is 5 and the corresponding numbers are 10 and 5
 If the array is 30, 20, 5, 20, 35, then your program should print
The minimum absolute difference is 0 and the corresponding numbers are 20 and 20

Solution
Problem 18

Consider a string of characters with no space between them (for example, a word in English), terminated by ‘\0’. You will write a C program to count and print the maximum consecutive occurrence of the same character, and the corresponding character. If there are multiple characters that occur consecutively the same number of times, you can print any one such character.

For example,  If the string is “aabbbccbbd”, then ‘a’ occurs two times consecutively, ‘b’ occurs maximum of three times consecutively, ‘c’ occurs two times consecutively, and ‘d’ occurs one time consecutively. So you should output the character ‘b’ and 3, since ‘b’ occurs the maximum number of times consecutively among all characters

 If the string is “pdslab”, there is no character that occurs more than once consecutively. So in this case, you should output the character ‘p’ and 1 (meaning that p occurred the max times (=1) consecutively). Note that you can also output any of the other characters in the string (instead of ‘p’), as they all occur exactly once

 Write a C function int CountChar(char C[ ], char *mc) that takes a string C of characters (terminated by ‘\0’) and returns the count of the maximum number of consecutive occurrence of the same character. It also puts the character with this maximum in mc.

Write a main function that does the following:
 Reads in an integer n
 Dynamically allocates a character array of size n
 Read in a string using %s in scanf (assume size of string will be < n)
 Call CountChar() to find the maximum number of consecutive occurrence of the same character in the string.
 Prints the maximum count and the character with the maximum count.

 If the string read is “aabbbccbbd”, your program should print
The character with maximum consecutive occurrence is b, with count 3

 If the string read is “aabbbccc”, your program should print either
The character with maximum consecutive occurrence is b, with count 3 Or
The character with maximum consecutive occurrence is c, with count 3 as both b and c occur 3 times consecutively

Solution
Problem 19

XYZ Pvt. Ltd. stores the following information for each of its employees:
– Name (max 20 characters including ‘\0’ at end), employee code (integer), age (integer), salary (floating point)
 Define a C structure named employee to store this data for each employee

 Write a function
int SearchEmpl(struct employee A[ ], int n, …) that will search for an employee with a specific employee code, and if found, will return his/her name, age and salary.
 A is the array of employee structures containing the records of all employees, and n is the number of such structures in A
 The return value should be 1 if the employee code matches a structure, 0 otherwise
 You will need to add other parameters required to return the age, salary and name

Write a main function that does the following:
 Declares a pointer p to point to an employee structure
 Reads in the number of employees n from the keyboard
 Mallocs an array of n number of employee structures and stores the return value of malloc in p
 i.e., holds the information for n employees, one employee structure for each employee
 This is your array of structures
 Reads in the name, employee code, age, and salary for the n employees one by one in a loop
 When you read the information for one employee, call the SearchEmpl() function to check if the employee code already exists. If yes, reject the information entered with a suitable message and ask the user to enter the information for this employee again.
 So finally you should have entered the information of n employees with distinct employee codes Reads in a floating point number k and print the name, employee code, age, and salary of all employees with salary > k
 Compare the salary field of the employee structure of each employee with k
 Print the name, employee code, age, and salary fields if salary field is > k
 Print the information for each such employee in a separate line  If there is no employee with salary > k, print a suitable message saying so
 Reads in an integer x
 Call the SearchEmpl() function with appropriate parameters to find if there is any employee with employee code x. If yes, print his/her name, age, and salary with an appropriate message
 If there is no employee with employee code x, print a suitable message saying so

Example
 n = 4,
 employee details read in array (< employee code, name, age, salary>)
< 1002, David, 32, 30000>
< 1010, John, 36, 40000>
< 1001, Mary, 35, 42000>
< 1005, Tom, 40, 50000>
 k = 40000
 x = 1001
Your program should print
Employees with salary greater than 40000 are
1001, Mary, 35, 42000
1005, Tom, 40, 50000
Employee with employee code 1001 is Mary, 35, 42000

Solution
Problem 20

Use structures in C programming to represent complex numbers with their real and imaginary parts [Hint: A complex number is denoted in the form X+iY, where X and Y are the real and imaginary parts.]. Input two complex numbers ‘a’ and ‘b’ from the user and perform the following operations on them.
(a) Add ‘a’ and ‘b’, and store the sum into a third complex number ‘c’. Print ‘a’, ‘b’, and ‘c’ in the format ‘X+iY’.
(b) Find out the magnitudes of ‘a’, ‘b’, and ‘c’ and print them. The magnitude of a complex number is sqrt(X2 + Y2).
(c) Find out the argument (or angle) of the three numbers ‘a’, ‘b’, and ‘c’. The argument of a complex number can be found out by performing tan−1(Y/X). Use the function atan() from for inverse tangent function.
Create user-defined functions for each of the aforementioned operations.

Solution
Problem 21

Implement a movie ticket booking system for a multiplex. Input the number of screens in the multiplex from the user. Create an array of structures for the multiplex, in which each element represents a screen. The structure definition of each screen should have the following elements.

• ID (integer not greater than number of screens)
• movie name (string of 20 characters max)
• remaining tickets (integer)
• ticket price (float)
• revenue earned (float).
Input the maximum tickets for each screen from the user. Write the following functions:

(a) checkAvailability - Input the movie name from the user, print the number of tickets available and the price.

(b) buyTicket - Input the movie name and number of tickets required from the user. Display total price if tickets are available (you may call the checkAvailability function here). Ask if the user wants to proceed. If the user agrees, print “Ticket booked”, reduce the number of available tickets, and increase the revenue earned by the ticket purchase amount.

(c) totalRevenue - Print the total revenue earned and remaining tickets for each of the screens. You can use strcmp() to check equality of strings from < string.h>.

Solution
Problem 22

Write a program to –
(a) Input two strings from the user and store them in two different arrays. Print the contents and addresses of the first elements of the arrays.
(b) Define a function swapString() to swap the contents of the two arrays using pointers (by passing array pointers into the function).
(c) Print the contents and addresses of the first elements of the two swapped arrays from the main function.
Note: You cannot use any in-built function for swapping

Solution
Problem 23

Write a program to –
(a) Input 5 strings from the user.
(b) Define an array of pointers such that each element of the array points to each of the strings.
(c) Define a function f indLength() to find the length of each of the strings. Pass the strings to the function using the pointers. (d) Define a function f indP alindro
me() to find the first palindrome string in the array. Print the address of the first and last character of the palindrome string found (Pass the strings to the function using the pointers).
Note: You cannot use any in-built function for any subpart.

Solution
Problem 24

Declare in main() two arrays a[ ] and b[ ] with 3 integers each, and fill up them using scanf().

Write a function swap(int *x, int *y, int n) that swaps the first n elements of the array x[ ] with the first n elements of the array y[ ].
Print the addresses of all the elements of x[ ] and y[ ].

Call swap() from main() to swap the first two elements of a[ ] with the first two elements of b[ ],
and print the elements of a[ ] and b[ ] from main(), along with their addresses.

Solution
Problem 25

Declare in main() two integers a and b, and read their values using scanf().

Write a function swap(int *x, int *y) that swaps the values stored at addresses x and y.
Print the addresses of x and y and the values (i.e., addresses) stored in x and y.

Print the addresses of a and b in main().
Call swap() from main() to swap the values of a and b, and print them in main().

Notice and explain yourself:
1. The values stored in x and y printed from swap() are ALWAYS same as the addresses of a and b in main().
2. The addresses in the following example may not match with those obtained by running the code on a different machine.

Enter a, b: 2 5

Addresses of a, b = 0x7ffccad073e0 0x7ffccad073e4
Addresses of x, y = 0x7ffccad073b8 0x7ffccad073b0
Addresses in x, y = 0x7ffccad073e0 0x7ffccad073e4
After swap: a, b = 5, 2.

Solution
Problem 26

Define a structure named "student" with the following fields: name and surname of 15 characters each, and cgpa as a real number.
Write a swap function that takes as input two student pointers a and b, and exchanges the data in the student records pointed by them. The return type of this function should be void.
In main(), declare two student-type variables, a and b. Take user input to fill up their fields. Call the swap function to exchange their data and then print the result from the main().

Enter the name, surname, CGPA of 1st student: ram singh 7.5
Enter the name, surname, CGPA of 2nd student: alice miller 6.9

After swapping:

Student 1: alice miller 6.90
Student 2: ram singh 7.50

Solution
Problem 27

Declare in main() two integer arrays a[] and b[] that can contain 100 numbers.
Take n as input and fill up a[] with n distinct integers using scanf().

Write a function of the prototype:
int find_wrong_order(int *x, int *y, int n, int i)
that fills up y[] with those elements in {x[0],...,x[i-1]} that are larger than x[i] and those in {x[i+1],...,x[n-1]} that are smaller than x[i],
and returns the number of elements filled up in y[].
Call find_wrong_order() from main() iteratively for each element a[i], i=1,2,...,n,
and use b[] to print from main() the elements of b[] and a[i] as they appear in a[].

Enter n: 3
Enter the elements of a[]: 2 1 3
[2] 1
2 [1]
[3]

Enter n: 3
Enter the elements of a[]: 3 2 1
[3] 2 1
3 [2] 1
3 2 [1]

Enter n: 3
Enter the elements of a[]: 1 2 3
[1]
[2]
[3]

Enter n: 4
Enter the elements of a[]: 3 2 4 1
[3] 2 1
3 [2] 1
[4] 1
3 2 4 [1]

Enter n: 5
Enter the elements of a[]: 7 2 6 3 4
[7] 2 6 3 4
7 [2]
7 [6] 3 4
7 6 [3]

7 6 [4]

Solution
Problem 28

Define a structure named student that contains the roll number (int), name, surname of a student, and his/her marks.
Read a file named stu.txt during execution of your program and populate an array of the structure student.
The first line of this file contains the number of students (max 100).

Print the students (with short names) whose marks are lowest and highest.
Assume that they are unique.


Lowest: V. Majety 41
Highest: J. Gupta 95

Solution
Problem 29

Define a structure called menu that contains the name of a food item (two strings) and its unit price (float).

Read a file named menu.txt during execution of your program to store all menu items and their respective unit prices in an array of structure.

Print on the terminal so that every item and its unit sale price (with 12.5% tax added) appear in a new line.

Print only the veg items.
Note the formatting in the example.

Assume that:
menu.txt contains the number of items in the 1st line.
menu.txt contains no more than 100 items.
How to take an input file (instead of terminal input) during execution of program:

1: cheese steak -------------- 61.88
2: potato steak -------------- 45.00
3: veg steak ----------------- 50.62
4: chicken steaks ------------ 67.50
5: fried potato -------------- 39.38
6: veg sandwiches ------------ 56.25
7: cheese sandwiches --------- 73.12
8: egg sandwiches ------------ 73.12
9: chicken sandwiches -------- 90.00
10: burger veg ---------------- 73.12
11: cheese burger ------------- 84.38
12: chicken burger ------------ 84.38
13: green salads -------------- 45.00
14: lemon tea ----------------- 5.62
15: milk tea ------------------ 8.44
16: black tea ----------------- 4.50
17: black coffee -------------- 5.62
18: milk coffee --------------- 8.44
19: sweet small --------------- 4.50
20: sweet large --------------- 7.31
=====================================
3: veg steak ----------------- 50.62
6: veg sandwiches ------------ 56.25
10: burger veg ---------------- 73.12
=====================================

Solution
Problem 30

Define a structure as: struct point{float x, y;};
Write a function that takes two points as input and returns their distance to the calling function (e.g., main()); its prototype will be:
float calculate_distance(struct point p, struct point q)

Declare an array of 100 points in main(): struct point a[100];

Take n as the number of points, fill up the array, and find the minimum distance among the n points.

Enter no. of points (2 to 100): 3
Enter (x,y) coordinates of the points:
0 0
3 3
2 2
Minimum inter-point distance = 1.414214

Enter no. of points (2 to 100): 3
Enter (x,y) coordinates of the points:
0.1 0.2
3.1 3.2
2.1 2.2
Minimum inter-point distance = 1.414214

Enter no. of points (2 to 100): 5
Enter (x,y) coordinates of the points:
11.11 22.22
22.22 33.33
33.33 44.44
44.44 55.55
55.55 66.66
Minimum inter-point distance = 15.711910

Solution
Problem 31

User gives a positive integer n (1 to 10) as input.
Your program should print all the numbers made of the digits 1 and 2 such that the sum of the digits is n.
It should also print the total number of such numbers at the end.
Use a recursive function and a global variable to keep track of the total.
You can use an array of length 10 but no other array.

Enter n: 1
1
-----------
Total = 1
-----------

Enter n: 2
2
11
-----------
Total = 2
-----------

Enter n: 3
21
12
111
-----------
Total = 3
-----------
Enter n: 4
22
211
121
112
1111
-----------
Total = 5
-----------

Enter n: 10
22222, 222211, 222121, 222112, 2221111, 221221, 221212, 2212111, 221122, 2211211, 2211121, 2211112, 22111111, 212221, 212212, 2122111, 212122, 2121211, 2121121, 2121112, 21211111, 211222, 2112211, 2112121, 2112112, 21121111, 2111221, 2111212, 21112111, 2111122, 21111211, 21111121, 21111112, 211111111, 122221, 122212, 1222111, 122122, 1221211, 1221121, 1221112, 12211111, 121222, 1212211, 1212121, 1212112, 12121111, 1211221, 1211212, 12112111, 1211122, 12111211, 12111121, 12111112, 121111111, 112222, 1122211, 1122121, 1122112, 11221111, 1121221, 1121212, 11212111, 1121122, 11211211, 11211121, 11211112, 112111111, 1112221, 1112212, 11122111, 1112122, 11121211, 11121121, 11121112, 111211111, 1111222, 11112211, 11112121, 11112112, 111121111, 11111221, 11111212, 111112111, 11111122, 111111211, 111111121, 111111112, 1111111111, -----------
Total = 89
-----------


You're supposed to input the files stu.txt for w07-1 and menu.txt for w07-2. The output format must be exactly the same or marks would be deducted.

Solution
Problem 32

Write a menu driven C program to keep records and perform statistical analysis for a class of 20 students. Each student attends in three different subjects (Maths, Physics, Chem). The information of each student contains Roll number (ID, string), Name, marks in three subjects and total score.

The program will prompt the user to choose the operation on records from a menu as shown below:
1 . Add student records
2. Delete student records (by roll number)
3. Update student records (Donot update the roll#. Update name and marks only)
4. View all student records
5. Calculate an average of a selected (by ID) student's scores
6. Show student who gets the max total score
7. Show student who gets the min total score
8. Find student by ID (simple linear search)
9. Identify the student who got highest marks in a given subject. Subject name should be taken as input.
10. Exit

Implement the student records using structure. Write suitable functions to implement the above tasks.

Solution
Problem 33

Declare an integer variable x and an integer pointer PX.
Assign the address of x to PX.
Assign a value to x taken as input from the user.
Print the address of x, the value of x, the address of PX, the content of PX, and the value stored in the address pointed by PX.
Now double the value of x.
Print again all the values and addresses, as mentioned above.

Example:
bash-3.00$ gcc 7a.c

Enter an integer: 5
address of x = 134509512, x = 5
address of = 134509508, = 134509512
value stored in the address pointed by PX = 5

Enter an integer: 7
address of x = 134509512, x = 7
address of = 134509508, = 134509512
value stored in the address pointed by PX = 7

Solution
Problem 34

Scan three integers as input in main() and store them in three variables, namely a, b, c.
Print their respective addresses and values.
Write a function with appropriate input parameters and call it from main() to rearrange the values of a, b, c, in non-decreasing order.
Print their respective addresses and values, from main().
Notice that the addresses of a, b, c remain unchanged, but their respective values are now sorted in non-decreasing order.

Example:
Enter three integers: 53 7
--Before function call----
Address of a = 341784
Address of b = 341788
Address of c = 341852
Values in a, b, c = 5, 3, 7
---After function call----
Address of a
= 341784
Address of b
= 341788
Address of c
= 341852
Values in a, b,c=3,5,7

Solution
Problem 35

Implement the "stack storage" using structure. In the "stack storage", you can insert and remove elements from only one end of the stack, termed as stack 'top'.
The insertion of the element is called push and removal of the element is called pop. Hence, the element, that you have pushed last, can be removed (popped) first (Last In First Out).
Write a C program to perform (1 ) push,(2) pop and (3) top operations. You may take the option as the input from the user (as 1, 2 and 3) and perform the required operations. The stack size is also taken from the user as an input value.
Push will take the input from the user and insert the element in the stack.
Pop operation removes the element from the stack, also prints the removed element. In addition, implement the top operation just to display the top element of the stack.
If there is no element in the stack, the pop operation will return "Stack Underflow" and the top operation will return "No Data". If the stack size reaches the maximum limit, push operation will return "Stack Overflow".
You should implement suitable functions to implement push, pop etc operations. The stack structure should contain (a) an array to store the stack elements (b) stack top index.
Example

Enter Stack size n: 5
Press 1 -> Push, 2 -> Pop, 3-> Top
Enter option: 3
No Data

Press 1 -> Push, 2 -> Pop, 3-> Top
Enter option: 2
Stack Underflow

Press 1 -> Push, 2 -> Pop, 3-> Top
Enter option: 1

Solution
Problem 36

Write a program to implement a queue using structures. In queue, you have two ends, namely 'front' and 'rear'.
The elements can be inserted at the rear end and can be removed from the front end.
Hence, the element, that you have inserted first, will be removed first (First In First Out).
Write a program to implement a queue using structures. The structure will contain the list of elements (of size MAX) and the index of the front and rear element.
Implement enque() and deque() operations. Enque() function will take the input from the user and insert the element in the queue.
Deque() removes the element from the queue, also prints the removed element.

Please remember, during enque(), the newly inserted element will be the rear element.
During deque(), the front element will be removed.

Solution