Professional Documents
Culture Documents
Assignment 4
Assignment 4
Spring 2022-23
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:
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]