You are on page 1of 2

Programming and Data Structure Laboratory (CS19001)

Spring 2022-23

Assignment for Week 4 (April 3, 2023)

Total Marks: 100 Duration: 3 hours

INSTRUCTIONS
a) All programs should be written in C.
b) The file containing your solution to problem ‘x’ should be named roll-week4-probx.c where ‘roll’ is your roll
number.
c) Use indentation and comments as necessary. You are allowed to consult your books, notes or manual pages.
d) Upload the three files separately on Moodle..

PROBLEMS

1. A number p is said to be a Sophie German prime if both the numbers p and 2p+1 are primes. Write a
function int is_prime(int n) that takes an integer n and returns 1 if n is prime and 0 otherwise.
Write a main function that reads two integers m and n, and calls the function is_prime to list all Sophie
German primes in the interval [m, n]. [30 marks]
Generate the output in proper formatted fashion as follows:

Enter the interval (two positive integers): 250 600


The Sophie German primes in [250, 600] are
251
281
293
359
419
431
443
491
509
593
---------------------------------------------

2. Write a function int reverse(int n) that takes a number n and returns a number with the digits of
n reversed. Also write a function int gcd(int m, int n) to compute and return the gcd of two
numbers m and n. Write a main function that reads three integers p, q and r, and computes the gcd of the
reversed version of the three numbers. [35 marks]

Generate the output in proper formatted fashion as follows:

Enter three positive numbers: 2961 9970 71500


The reversed numbers are: 1692, 799 and 517
GCD (1692, 799, 517) = 47
---------------------------------------------
3. Write a program to read a positive integer N, and then read N numbers of type double into a one-
dimensional array A. Compute and print the following:
a) The mean and standard deviation of all the numbers in the array A up to three decimal places.
b) The minimum and maximum numbers in the array A.
c) How many numbers in the array are larger than the mean? [35 marks]
Generate the output in proper formatted fashion as follows:

Enter the value of N: 6


Enter the numbers: 12.5 -3.2 55.1 40 -1.85 44.25
Mean = 24.467
Standard deviation = ?????
Minimum = -3.2
Maximum = 55.1
3 numbers are greater than the mean
---------------------------------------------

You might also like