0% found this document useful (0 votes)
5 views

Offline4 Pointers

Uploaded by

Nafis Iqbal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Offline4 Pointers

Uploaded by

Nafis Iqbal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

January 2024 CSE 102

Offline 4: Pointers

Total Marks: 10+ 10= 20

Problem 1: Reverse Words in a String


Problem Description: Take a string, s, as input and reverse the order of the words. A
word is defined as a sequence of non-space characters. The words in s will be
separated by at least one space. If there are any extra spaces remove this in the output
string.

Constraints:

• Do not use array of some predefined size. Use pointer arithmetic and
dynamic memory allocation. You can only use two dynamically allocated
arrays; one for input string and another for output string. No additional arrays
can be used.
• You must write a function named void reverseWords(char *a, char *t)
where char *a is the input string and char *t is the output string.
• Array indexing notation is not allowed. (i.e., you must use *(p + i) instead of
p[i]).

Sample Input(s) Corresponding Output(s)

"the sky is blue" "blue is sky the"

" hello world " "world hello"


Problem 2: Mode
Find the mode of some given numbers. The mode of some numbers is/are the ones
which appear the highest number of times. Take an integer n as input. Next take n
integer elements as input, whose mode you need to find. All the inputs will have values
in [0, 10000] range. (Hint: Note the upper limit; you can count frequencies for this.
Suppose you created an array using dynamic memory allocation and p is a pointer to
the first address of this array. Count the frequency of an integer i and store the count in
*(p+i).) Print the mode(s) of the given numbers. Use pointer arithmetic and dynamic
memory allocation. Do not use array of some predefined size. Do not use array
indexing.

Sample Input(s) Corresponding Output(s)


3 1
1 3 1
4 2
2 2 1 4
5 1 4
1 2 1 4 4

Submission Guidelines:
1. Go to a drive except C drive.
2. Create a folder according to your roll number. Ex- 2305xxx.
3. Open up the folder and create two files there. Ex- 2305xxx-1.c, 2305xxx-2.c.
4. Place all the code inside the two .c files.
5. Zip the folder and submit it in the moodle.

You might also like