Ramesh Bandaru Page 10
/* Program to implement Towers of Hanoi using Recur sion function*/
void towers(int, char, char, char);
void main()
{
int num;
clrscr();
printf(“Enter number of disks :”);
scanf(“%d”,&num);
towers(num, ‘A’,’C’,’B’);
}
void towers(int n, char src, char dest, char aux)
{
if(n==1)
printf(“Move from %c to %c\n”,src,dest);
else
{
towers(n-1, src, aux, dest);
printf(“Move from %c to %c\n”,src,dest);
towers(n-1, aux, dest, src);
}
}
Output
Enter number of disks : 3
Move from A to C
Move from A to B
Move from C to B
Move from A to C
Move from B to A
Move from B to C
Move from A to C
Standard Library Functions
C provides a rich collection of standard functions whose definition have been written and are
ready to be used in our programs. To include functions, we must include their function declarations. The
function declarations for these functions are grouped together and collected in several header files.
Instead of adding individual function declarations of each function, we simply include the headers at the
top of our file.
Math Functions
Many important library functions are available for mathematical calculations. Most of the function
declarations for these functions are in either math header file (math.h) or standard library (stdlib.h). In
general, the integer functions are found in stdlib.h.
1) Absolute Value functions
An absolute value is the positive rendering of the value regardless of its sign. There are three
integer functions and three real functions.The integer functions are abs, labs, llabs . The real
functions are fabs, fabsf, fabsl. Examples are
abs(6) returns 6