Professional Documents
Culture Documents
Main
Main
Lab Test 2
1. Do not use any global variable unless you are explicitly instructed so.
3. Name your file as <roll_no>_<assignment_no>. For example, if your roll number is 14CS10001
and you are submitting assignment 3, then name your file as 22CS10001_3.c. For lab test 1, write
22CS10001_labtest1.c and for lab test 2, write 22CS10001_labtest2.c.
4. If you are asked to submit more than one program, then name your file as
<roll_no>_<assignment_no>_part<part_number>. For lab tests, use the naming conven-
tion specified in 3.
5. Write your name, roll number, assignment number, and PC number at the
beginning of your program.
6. Make your program as efficient as possible. Follow best practices of programming.
Submit one C program (.c file) for each part in CSE Moodle. Hence, submit two
C programs.
Even PC number
Part I
Write a C program that takes one positive integer k as input and prints all positive integral solutions of
the following equation.
a+b+c=k
Sample Output
Write k: 5
a=1 b=1 c=3
a=1 b=2 c=2
a=1 b=3 c=1
a=2 b=1 c=2
a=2 b=2 c=1
a=3 b=1 c=1
1
Part II
Write a C program which (i) takes the number n of names as input, then (ii) takes n names (assume each
name is at most 30 characters long) as input and stored in a dynamically created array of appropriate
size, and then (iii) sort them in reverse-lexicographic order using bubble sort.
Sample Output
Write n: 5
Write 5 names
Rahul
Rita
Ajay
Saheli
Vikas
Reverse-lexicographic order of these 5 names:
Vikas
Saheli
Rita
Rahul
Ajay
2
Odd PC number
Part I
Write a C program that takes two positive integers k and ℓ as input and prints all permutations with k
red balls and ℓ green balls.
Sample Output
Write k: 4
Write l: 2
RRRRGG
RRRGRG
RRRGGR
RRGRGR
RRGGRR
RGRGRR
RGGRR
GRGRR
GGRRR
RRGRRG
RGRRGR
GRRGRR
RGRRRG
GRRRGR
GRRRRG
Part II
Write a C program which (i) takes the number n of names as input, then (ii) takes n names (assume each
name is at most 30 characters long) as input and stored in a dynamically created array of appropriate
size, and then (iii) sort them in lexicographic order using insertion sort.
Sample Output
Write n: 5
Write 5 names
Rahul
Rita
Ajay
Saheli
Vikas
Lexicographic order of these 5 names:
3
Ajay
Rahul
Rita
Saheli
Vikas