0% found this document useful (0 votes)
23 views2 pages

Assignment 6

iit kgp advanced caclculus assignment 6

Uploaded by

akshath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Assignment 6

iit kgp advanced caclculus assignment 6

Uploaded by

akshath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CS19003 Programming and Data Structures

Assignment 6

General instruction to be followed strictly

1. Do not use any global variable unless you are explicitly instructed so.

2. Use proper indentation in your code and comment.

3. Name your file as <roll_no>_<machine_no>_t1.

4. Write your name, roll number, and test number at the beginning of your program.

5. Make your program as efficient as possible.

Write a C program for the following problem

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.

3. In the main function:

▷ 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.

You might also like