Pages

Friday 22 February 2019

Program to find multiplication using recursion.

Program to find multiplication using recursion.

mul(a,b) = a                        b=1 // Base case
              = a + mul(a,b-1)    b>1 // Recursive case

// recursion program on multiplication
#include<stdio.h>
int a,b,c;   /* global variable */
int mul(int,int); /* function declaration */
void main()
{
 int c;
 printf("\n enter any two numbers:\n");
 scanf("%d%d",&a,&b);
 c=mul(a,b);
 printf("multiplication of %d and %d = %d",a,b,c);
}

int mul(int a,int b)
 {
  if(b==1)
  return a;
  else
  c=a+mul(a,b-1);
  return (c);
 }

output:

No comments:

Post a Comment

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...