46. Find the even number from a array by using RECURSION

Question: Get input a array frmon user and find the hight number. You can only use one array and can not use any globel variable.

Ans: If you can use more then one array then you can easyle find the hight number by only using for loop. But you can not use more then one array. So you can solve this problem by using recursion.

/*program for find the even number */

#include<stdio.h>
#include<conio.h>

int main()
{
clrscr();
int a[100];n,i;
printf("How many number you want to input: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the %d number: ");
scanf("%d",&a[i]);
}
void chk_evn(int,int,int*,int*)
chk_evn(0,0,&n,a);
for(i=0;i<n;i++)
printf("%d",a[i]);
return 0;
}

void chk_evn (int i,int j,int *n,int *a)
{
if(i==n){*n=j;return n;}
if(a[i]%2==0)
a[j++]=a[i];
chk_evn(i+1;j,n,a);
}

program written by arnob

No comments:

Post a Comment

free counters