recursion prog n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Recursion Prog PowerPoint Presentation
Download Presentation
Recursion Prog

Loading in 2 Seconds...

play fullscreen
1 / 9

Recursion Prog - PowerPoint PPT Presentation


  • 83 Views
  • Uploaded on

Addition of 2 nos. #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 = %d\n",i); getch(); } int add(int addk,int addm){ if(addm==0) return(addk); else

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Recursion Prog' - jefferson-tommy


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
recursion prog

Addition of 2 nos

#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 = %d\n",i);

getch();

}

int add(int addk,int addm){

if(addm==0)

return(addk);

else

return(1+add(addk,addm-1));

}

Recursion Prog

recursion prog1

Power function

#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 );

}

Recursion Prog

recursion prog2

Even sum

#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(inti,int n){

static int even=0;

if(i<=n){

even=even+i;

sum(i+2,n); //calling same function

}

return even;

}

Recursion Prog

recursion prog3

Reverse String

#include<string.h>

void reverse(char [],int b);

void main()

{

char a[26];

intlen;

clrscr();

printf("enter string ");

Scanf(“%s”,a);

len=strlen(a);

reverse(a,len);

getch();

}

void reverse(char a[],int len)

{

if(len==0)

printf("%c",a[len]);

else

{

printf("%c",a[len]);

reverse(a,len-1);

}

}

Recursion Prog

recursion prog4

Reverse Number

#include<conio.h>

#include <stdio.h>

int sum=0,r;

void main()

{

int reverse(int);

intnum,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;

}

Recursion Prog

recursion prog5

Fibnocci Series

void main()

{

long term(int);

inti,n;

clrscr();

printf(“Enter Limit”);

scanf("%d",&n);

printf("\nThe Series is :”);

for(i=1;i<=n;i++)

{

printf(" %ld ",term(i));

}

getch();

}

long term(int n)

{

if(n==1)

return(0);

else if(n==2||n==3)

return 1;

else

return(term(n-1)+term(n-2));

return 0;

}

Recursion Prog

recursion prog6

Print Pattern

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);

}

}

Recursion Prog

recursion prog7

Print Nos in Descending 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-1);

}

}

Recursion Prog

recursion prog8

Print EVEN Nos in Descending 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);

}

}

Recursion Prog