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 – 1 (Section 18)


[ODD PC #]
-------------------------------------------------------------------------------------------------------
Date & Time: 12th Sept 2023 & 2PM Total Marks = 100 Time: 2 hrs
-------------------------------------------------------------------------------------------------------
1. Write a C program to print the lengths and elements of top 3 max-length sequences based on
their first occurrence in the given set of integers. The sequence to be searched should consists
of same integer. The size of the set (n) as well as the elements of the set will be taken from the
user through keyboard. (60M)

Example-1:
Size of the set (n) = 10
Input : 25 23 23 23 23 15 15 1 1 1
Length of Seq-1 = 4 : 23 23 23 23
Length of Seq-2 = 3 : 1 1 1
Length of Seq-3 = 2 : 15 15

Example-2:
Size of the set (n) = 15
Input : 25 23 23 23 23 15 15 1 1 1 1 -9 -9 -9 -9
Length of Seq-1 = 4 : 23 23 23 23
Length of Seq-2 = 4 : 1 1 1 1
Length of Seq-3 = 4 : -9 -9 -9 -9

Example-3:
Size of the set (n) = 15
Input : 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6
Length of Seq-1 = 3 : 1 1 1
Length of Seq-2 = 3 : 2 2 2
Length of Seq-3 = 3 : 3 3 3

Example-4:
Size of the set (n) = 5
Input : 25, 23, 15, 1, -9
Length of Seq-1 = 0 :
Length of Seq-2 = 0 :
Length of Seq-3 = 0 :

2. Write a C program to compute the cosine of x cos(x) approximately by summing the first n
2 4 6
x x x
terms of the infinite series cos x =1− + − + … where x is expressed in radians.
( )
2! 4! 6!
Continue adding successive terms in the series until the absolute value of the difference
between the successive terms becomes smaller than 10-5 . Test your program for different
values of x (-10 to 10) and display the number of terms and value of cos(x). (40M)
Department of Computer Science & Engineering IIT Kharagpur
PDS Lab Test – 1 (Section 18)
[EVEN PC #]
-------------------------------------------------------------------------------------------------------
Date & Time : 12th Sept 2023 & 2PM Total Marks = 100 Time: 2 hrs
-------------------------------------------------------------------------------------------------------
1. Write a C program to print the lengths and the last elements of top 3 max-length sequences
based on their first occurrence in the given set of integers. The sequence to be searched
should not consists of same integer in adjacency. The size of the set (n) as well as the
elements of the set will be taken from the user through keyboard. (60M)

Example-1:
Size of the set (n) = 10
Input : 1 2 3 3 3 4 5 6 6 7
Length of Seq-1 = 4 : 6
Length of Seq-2 = 3 : 3
Length of Seq-3 = 2 : 7

Example-2:
Size of the set (n) = 10
Input : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Length of Seq-1 = 0 :
Length of Seq-2 = 0 :
Length of Seq-3 = 0 :

Example-3:
Size of the set (n) = 15
Input : 1 2 3 3 4 5 5 6 7 7 8 9 9 10 11 12
Length of Seq-1 = 3 : 3
Length of Seq-2 = 3 : 5
Length of Seq-3 = 3 : 7

Example-4:
Size of the set (n) = 5
Input : 25, 23, 15, 1, -9
Length of Seq-1 = 5 : -9
Length of Seq-2 = 0 :
Length of Seq-3 = 0 :

2. Write a C program to compute the sine of x approximately by summing the first n terms of
x3 x 5 x 7
the infinite series sin ( x )=x− + − +… where x is expressed in radians. Continue
3! 5! 7!
adding successive terms in the series until the value of the next term becomes smaller than
10-5 . Test your program for different values of x (-10 to 10) and display the number of terms
and value of sin(x). (40M)

You might also like