Assignment 6
Assignment 6
Assignment 6
1. Do not use any global variable unless you are explicitly instructed so.
4. Write your name, roll number, and test number at the beginning of your program.
1. Write a function compare(. . .) that takes as input two strings t1 and t2 and returns the number of
indices where the two strings differ. If the index of one string holds the null character while the
other holds a non-null character then that index will be counted towards the number of indices
where the two strings differ. Eg. Cat and Cattle will have 3 indices where the two strings differ.
Dog and Boggle will have 4 indices where the two strings differ.
2. Write a function xor(. . .) that takes as input two strings t1 and t2 and returns a string t such that for
each index, (i) if the characters of t1 and t2 are the same, then the character of t is that character,
(ii) if one of the characters is the null character then the character of t is the null character, (iii) if
both the characters are non-null then the character of t is set to ’a’. Eg. PDS and LAB will result in
aaa, PDS and LAB1 will result in aaa, PDS and PCLAB1 will result in Paa.
▷ Define a 2D array A that can hold at most 100 strings of length 100 each.
▷ Take as input a positive integer n ⩽ 100.
▷ Ask the user to input n strings s1 , s2 , . . . , sn each of length at most 100. Store these strings in
A.
▷ Ask the user to input one more string s of length at most 100.
▷ Use compare(. . .) to calculate and output the number of indices where si and s differ for each
1 ⩽ i ⩽ n.
▷ For each 1 ⩽ j ⩽ 100, find out the character cj that appears the most number of times in the
j-th column of A. If the column is empty, then cj is defined as a null character. Construct a
string s ′ such that the j-th index of s ′ is cj , 1 ⩽ j ⩽ 100.
▷ Use xor(. . .) to return the string ŝ that is formed by taking the xor of the two strings s and s ′ .
▷ Output ŝ.
1
You may write auxiliary functions, other than those mentioned in the assignment, to help your
code.
You may need to use math library function: #include < math.h >
If you want to compile using the terminal then use the command
gcc ./program.c -lm
Proper commenting, indentation and output commands carry marks.
Policy on Plagiarism
Academic integrity is expected of all the students. Ideally, you should work on the assignment/exam
consulting only the material we share with you. You are required to properly mention/cite anything else
you look at. Any student submitting plagiarised code will be penalised heavily. Repeated violators of our
policy will be deregistered from the course. Read this to know what is plagiarism.