Last active
August 29, 2015 14:14
-
-
Save eroltutumlu/721504e2d24fa798972e to your computer and use it in GitHub Desktop.
Recursive Func. Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Bir sayının tersini özyinemeli olarak alıyor. | |
| // Fibonacci serisi ve faktöriyel örnekleride özyinemeli olarak daha rahat çözülebilir. | |
| #include <stdio.h> | |
| #include <math.h> | |
| int main(void) | |
| { | |
| int number; | |
| int length=0; | |
| printf("Number: "); | |
| scanf("%d",&number); | |
| int temp=number; | |
| while(temp!=0) | |
| { | |
| length++; | |
| temp/=10; | |
| } | |
| int result=Reverse(number,length); | |
| printf("%d",result); | |
| return 0; | |
| } | |
| int Reverse(int n,int len) | |
| { | |
| if(len==1) | |
| { | |
| return n; | |
| } | |
| else | |
| { | |
| return (((n%10)*pow(10,len-1))+Reverse(n/10,--len)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment