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

15CSE180 Computer Programming Laboratory

Lab 5
04 January 2019
 Functions

1. Write a C function oddReven() to find whether a given number is odd or even.
Write a C program that calls the above function and print the oddness/evenness
of all numbers from 1 to 100. 

2. Write a C function factorial() to find the factorial of a given number. Write
a C program that calls factorial() to print the factorial of all numbers from 1
to 20. (Note: The factorial of a number grows very fast. So decide the variable
type accordingly!!)

3. Write a C function isPrime() to find whether a given number is prime or not.
Write a C program that calls  isPrime()  and prints the primality of all the
numbers from  to 100.

4. Write  C   function  dec2bin()  finds   the   binary   equivalent   of  a   given   decimal
number. Write a C program that calls dec2bin() to print the binary equivalent
of all numbers from given interval.

5. Write  a C  function  sqroot()  that finds  the  square root  of  a given number.


Given below is the algorithm for finding the square root.

6. Write a C function factors() that find the factors of a given number. Write a
C program that calls  factors()  to print all the factors of numbers from 1 to
20.

7. Write   a   C   function  nthPower()  that   takes   as   input   a   number   and   n   and


calculates   the   nth   power   of   the   number.   Write   a   c   program   that   callls
nthPower() and prints the 1st to 10th power of a given number.
8. Write a function  cuberoot()  to calculate the cuberoot of the given number.
Use the algorithm given for square root above. For improving the guess use

where y is the cuberoot approximation of x

You might also like