Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recursion It is a process of calling the same function itself again and again until some condition is satisfied. Syntax: func1() { ……….. func1(); }

Similar presentations


Presentation on theme: "Recursion It is a process of calling the same function itself again and again until some condition is satisfied. Syntax: func1() { ……….. func1(); }"— Presentation transcript:

1 Recursion It is a process of calling the same function itself again and again until some condition is satisfied. Syntax: func1() { ……….. func1(); }

2 Example #include void main() { int a; int rec(int); printf("\nEnter the number:"); scanf("%d",&a); printf("The factorial of %d! is %d",a,rec(a)); }

3 int rec(int x) { int f; if(x==1) return(1); else f=x*rec(x-1); return(f); } Output: Enter the number:5 The factorial of 5! is 120

4 Example: Working of 3!

5 Tower of Honoi 1 2 3 32 3 1 3 2 3

6 1 2 3 32 3 1 3 2 3

7 Library Function It is pre-defined function. The library function provides functions like mathematical, string manipulation etc,.

8 Example sqrt(x): It is used to find the square root of x Example: sqrt(36) is 6 abs(x): It is used to find the absolute value of x Example: abs(-36) is 36 pow(x,y): It is used to find the value of x y Example: pow(5,2) is 25 ceil(x): It is used to find the smallest integer greater than or equal to x Example: ceil(7.7) is 8

9 rand(): It is used to generate a random number. sin(x): It is used to find the sine value of x Example: sin(30) is 0.5 cos(x): It is used to find the cosine value of x Example: cos(30) is 0.86 tan(x): It is used to find the tan value of x Example: tan(30) is 0.577

10 toascii(x): It is used to find the ASCII value of x Example: toascii(a) is 97 toupper(x): It is used to convert lowercase character to uppercase. Example: toupper(‘a’) is A toupper(97) is A tolower(x): It is used to convert uppercase character to lowercase. Example: tolower(‘A’) is a

11 Example: #include void main() { int x,y=2; printf("\nEnter the number:"); scanf("%d",&x); printf("\nThe squareroot of %d is %f",x,sqrt(x)); printf("\nThe value of %d power%dis%f ",x,y,pow(6,2));

12 printf("\nThe ceiling of 6.7 is %f",ceil(6.7)); printf("\nThe floor of 6.7 is %f",floor(6.7)); printf("\nThe absolute value of -6 is %d",abs(-6)); printf("\nThe value of sin 45 is %f",sin(45)); printf("\nThe uppercase of 'a' is %c",toupper('a')); printf("\nThe uppercase of 97 is %c",toupper(97)); getch(); }

13 Output: Enter the number:6 The squareroot of 6 is 2.449490 The value of 6 power 2 is 36.000000 The ceiling of 6.7 is 7.000000 The floor of 6.7 is 6.000000 The absolute value of -6 is 6 The value of sin 45 is 0.850904 The uppercase of 'a' is A The uppercase of 97 is A


Download ppt "Recursion It is a process of calling the same function itself again and again until some condition is satisfied. Syntax: func1() { ……….. func1(); }"

Similar presentations


Ads by Google