SHOW:
|
|
- or go back to the newest paste.
1 | - | // code for recurssion using function |
1 | + | // Upendra code for recurssion using function |
2 | #include <stdio.h> | |
3 | #include <math.h> | |
4 | int fun(int); | |
5 | int main() | |
6 | { | |
7 | int a,result; | |
8 | printf("Enter the no \n"); | |
9 | scanf("%d",&a); | |
10 | result=fun(a); | |
11 | printf("Reverse result is %d",result); | |
12 | } | |
13 | ||
14 | int fun(int a) | |
15 | { | |
16 | int r,c=-1,b=a,p; | |
17 | if (a!=0) | |
18 | { | |
19 | r=a%10; | |
20 | do | |
21 | { | |
22 | b=b/10; | |
23 | c=c+1; | |
24 | } | |
25 | while(b!=0); | |
26 | p=pow(10,c); // pow(10,c) = 10^c , if you include "#include<math.h>" at top then you can use power function i.e pow(x,y) ..... | |
27 | return (r*p+fun(a/10)); | |
28 | } | |
29 | } |