Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Department of Computer Science & Engineering, IIT Kharagpur

PDS Lab Test – 2 (Section 18), Autumn 2023-24


[ODD PC #]
-------------------------------------------------------------------------------------------------------
Date & Time: 7th Nov 2023 & 2PM Total Marks = 100 Time: 2 hrs
-------------------------------------------------------------------------------------------------------
1. Write a C program to input an array of n integers [positive (includes zero) and negative integers]
through keyboard. After the array has been filled up, display the elements of the array. Rearrange
the array such that the sequence of the elements follows opposite polarities from the beginning
of the array till the availability of the elements with opposite polarity. (40M)
(No additional array can be used)

Example-1:
Size of the array n = 10
Input: -1 -5 0 1 2 9 -3 7 8 -11
Rearranged array = -1 0 -5 1 -3 2 -11 9 7 8

Example-2:
Size of the array n = 4
Input: -1 -5 -3 -11
Rearranged array = -1 -5 -3 -11

2. Write a C program to capture the list of words from the user through keyboard and rearrange
the list of words in increasing order based on their length. Write the following C functions to
perform the sub-tasks of the main problem. (60M)

void input_words(char **, int n)


void display_words(char **, int n)
void order_words_length(char **, int n, char **)

Use DMA for appropriate allocation of memory to the list of words. Call the above function
from the main() to capture the words, display the words, rearrange the words and display the
rearranged sequence of words.

Example :
Number of words n = 5
Input: Rao, Kolkatta, KGP, krishna, total
Rearranged list of words: Rao, KGP, total, krishna, Kolkatta
Department of Computer Science & Engineering, IIT Kharagpur
PDS Lab Test – 2 (Section 18), Autumn 2023-24

[EVEN PC #]
-------------------------------------------------------------------------------------------------------
Date & Time: 7th Nov 2023 & 2PM Total Marks = 100 Time: 2 hrs
-------------------------------------------------------------------------------------------------------

1. Write a C program to input an array of n positive integers (> 0) through keyboard. After the
array has been filled up, display the elements of the array. Rearrange the array such that the
sequence of the elements follows alternatively even and odd property from the beginning of
the array till the availability of the elements with the above requirement. (40M)
(No additional array can be used)
Example-1:
Size of the array n = 10
Input: 9 7 6 4 1 3 5 2 4 8
Rearranged array = 9 6 7 4 1 2 3 4 5 8

Example-2:
Size of the array n = 5
Input: 1 3 5 7 9
Rearranged array = 1 3 5 7 9

2. Write a C program to capture the list of words from the user through keyboard and rearrange
the list of words in alphabetical order (dictionary-order). Write the following C functions to
perform the sub-tasks of the main problem. (60M)

void input_words(char **, int n)


void display_words(char **, int n)
void order_words_dictionary(char **, int n, char **)

Use DMA for appropriate allocation of memory to the list of words. Call the above function
from the main() to capture the words, display the words, rearrange the words and display the
rearranged sequence of words.

Example:
Number of words n = 5
Input: Rao, Kolkatta, KGP, krishna, total
Rearranged list of words: KGP, Kolkatta, Rao, krishna, total

You might also like