Sie sind auf Seite 1von 6

CSE 110 Home Assignment 2

Submission Guidelines:
1. There are 8 problems in this assignment. You need to solve each of them.
2. Submission Steps:
a. In your local machine, create a new folder; the name of the folder
should be your 7 digit roll number (e.g. 1806001). [​Note: Do not
start your roll number with “20”.​]
b. For each problem that you choose to solve, code your solution in a
.c file. ​The name of each file should be exactly like <your 7 digit
roll no>_problem1.c, <your 7 digit roll no>_problem2.c etc
(e.g., 1806001_problem1.c, 1806002_Problem2.c)​. Put these C
files in the folder created in (a)
c. Finally, zip the folder created in (a) to produce a .zip file. The
name of the .zip file should be your 7 digit roll number. (e.g.
1806001.zip) [​Note: Do not mail .rar files.​]
d. E-mail the zip file as an attachment. The subject line should :
Week_10 Offline <roll_number>. (e.g.Week_3 Offline 1806001).
Send your email to ​offlinesubmissions@gmail.com
3. Do not copy code. Even not from internet. ​You will be caught and harshly
dealt with.
4. Adhere to the input/output formats strictly. Your code may be run and
checked using an automated system.
5. In addition to submitting following the above mentioned submission
steps, bring your code to the next sessional class. You must be able to
explain your code properly.

Submission Deadline: ​The deadline or the last time to email the home
assignment is 11:55PM, August 21, 2019 (Wednesday) (Bangladesh
Standard time).
Problem 1
Marks: 10

Write a C program take three strings (maximum length of a string would be 50)
as input. Using a function find out the occurrences of second string inside the
first string, and replace those occurrences with third string. [Use call by
reference method. Use pointer arithmetic and dynamic memory allocation
(malloc). You cannot use array anywhere in the program.]

Sample Input Corresponding Output

Hello World Higher World


ello
igher

Hello World Hellabc Wabcrld


o
abc

abcde abcde
abd
xy
Problem 2
Marks: 10

Write a C program that takes an integer number ​n followed by ​n strings. Sort the
strings in dictionary order. Consider that, only uppercase letters will be given.
[Don’t use array anywhere in the program. Use pointer arithmetic and dynamic
memory allocation (malloc).]

Sample Input Corresponding Output

4 ABC
MNO ABCD
ABCD MNO
ABC XYZ
XYZ
Problem 3
Marks: 10

Write a C program that takes the dimension ​d of a 2-D square matrix followed
by the elements of the matrix. Then the program will start taking input for a
variable ​x​. If ​x=1,​ the program will clockwise rotate the peripheral elements of
the matrix. If ​x=0,​ it will rotate anti-clockwise. If the input is otherwise, it will
terminate the program.

For example, if ​d=4 and the matrix is as shown below (peripheral elements are
shown in bold face)

1​ ​2 3 2

4​ 5 6 ​1

7​ 8 9 ​2

8257

Then if ​x=1 t​ he matrix will become

8741

2562

5893

7212

If the user gives ​x=1​ again, then the matrix will become

7528

2567

1894

2321

Now, if the user gives ​x=0​ the matrix will be anti-clockwise rotated as follows
8741

2562

5893

7212

If the user gives ​x=5​ the program terminates.

Write the program without using any extra array. Note that, the maximum
dimension of the matrix would be 10x10.

Problem 4
Marks: 10

Write the above C program using pointer arithmetic and dynamic memory
allocation (malloc). You cannot use array anywhere in the program.

Problem 5
Marks: 10
Write a C program which takes a string as input (maximum length would be 50)
and find the length of the string using recursive function.

Sample Input Corresponding Output

Abc de 6
xyzw 4
Problem 6
Marks: 10

Write a C program using recursive function that takes some integers as input
until the number of negative integers is equal to the number of positive integers.
Then, it will print all the integers taken as input in the reverse order of their
entry. You cannot use any array, malloc function, global variable or static
variable for the program​.

Sample Input Corresponding Output

10 -5
-5 10
15 -25
25 -2
-6 5
19 -1
-5 -1
21 26
26 21
-1 -5
-1 19
5 -6
-2 25
-25 15

Problem 7
Marks: 10

Write a C program that takes an integer number as input, and finds out the
number of 1’s in the lowest byte of that integer using bitwise operator.

Sample Input Corresponding Output

319 6
15 4
Problem 8
Marks: 10

Write a C program that receives an unsigned 32-bit integer and then exchange
the contents of its higher 2 bytes with lower 2 bytes.

Sample Input Corresponding Output

325011 4120051716
98304 2147483649

Explanation:
For the first example,
Bit pattern of 325011 (which is held by an unsigned variable) is 00000000
00000100 11110101 10010011
After exchanging higher 2 bytes with lower 2 bytes we get
11110101 10010011 00000000 00000100 which is the bit pattern of
4120051716.
For the second example,
Bit pattern of 98304 (which is held by an unsigned variable) is 00000000
00000001 10000000 00000000
After exchanging higher 2 bytes with lower 2 bytes we get
10000000 00000000 00000000 00000001 which is the bit pattern of
2147483649.

Das könnte Ihnen auch gefallen