Your SlideShare is downloading. ×
Recursion prog (1)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Recursion prog (1)

45
views

Published on

Published in: Education, Technology, Business

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
45
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Addition of 2 nos Recursion Prog #include <stdio.h> #include<conio.h> main() { int add(int pk,int pm); int k = 2; int i; int m = 3; clrscr(); i = add(k,m); printf("i = %dn",i); getch(); } int add(int addk,int addm){ if(addm==0) return(addk); else return(1+add(addk,addm-1)); }
  • 2. Power function Recursion Prog #include<conio.h> #include <stdio.h> int main() { double power(double x, int n); double x = 0.0; int n = 0; clrscr(); printf("%lf",power(3,2)); getch(); } double power(double x, int n) { if(n == 0) return 1.0; else return x * power( x , n - 1 ); }
  • 3. Even sum Recursion Prog #include<conio.h> #include <stdio.h> void main() { int sum(int,int ); int total; total=sum(2,4); clrscr(); printf("%d",total); getch(); } int sum(int i,int n){ static int even=0; if(i<=n){ even=even+i; sum(i+2,n); //calling same function } return even; }
  • 4. Reverse String Recursion Prog #include<string.h> void reverse(char a[],int len) void reverse(char [],int b); { void main() if(len==0) { printf("%c",a[len]); char a[26]; else int len; { clrscr(); printf("enter string "); printf("%c",a[len]); Scanf(“%s”,a); reverse(a,len-1); len=strlen(a); } reverse(a,len); } getch(); }
  • 5. Reverse Number Recursion Prog #include<conio.h> #include <stdio.h> int sum=0,r; void main() { int reverse(int); int num,rev; clrscr(); printf("nEnter a number :"); scanf("%d",&num); rev=reverse(num); printf("nAfter reverse the no is :%d",rev); getch(); } Int reverse(int num) { if(num>0) { r=num%10; sum=sum*10+r; reverse(num/10); } else{ return sum; } return sum; }
  • 6. Fibnocci Series Recursion Prog void main() { long term(int); long term(int n) int i,n; { clrscr(); if(n==1) printf(“Enter Limit”); return(0); scanf("%d",&n); else if(n==2||n==3) printf("nThe Series is :”); for(i=1;i<=n;i++) return 1; { else printf(" %ld ",term(i)); return(term(n} 1)+term(n-2)); getch(); return 0; } }
  • 7. Print Pattern Recursion Prog main() { int i,n; void pat(int); clrscr(); for(i=1;i<=10;i++) { pat(i); } getch(); } void pat(int n) { if(n<1) printf("n"); else { printf("%d ",n); n=n-1; mult(n); } }
  • 8. Print Nos in Descenting ordre Recursion Prog main() { int i,n; void de(int); clrscr(); de(20); getch(); } void de(int n) { if(n==0) return(0); else { printf("n %d",n); de(n-1); } }
  • 9. Recursion Prog Print EVEN Nos in Descenting ordre main() { int i,n; void de(int); clrscr(); de(20); getch(); } void de(int n) { if(n==0) return(0); else { printf("n %d",n); de(n-2); } }

×