Problem Statement
Write a c program to take input from user and save them in an array
them calculate the maximum number using recursion
int largest(int a[],int i,int max);
int main()
{
int i,s,a[43],y,max;
printf("enter the number and enter ctrl d in the end \n");
i=0;
while(scanf("%d",&s)!=EOF)
{
a[i]=s;
i++;
}
max=a[i-1];
y=largest(a,i,max); /* i is actual number of elements */
printf("the largest number is %d \n",y);
return 0;
}
int largest(int a[],int i,int max)
{
if(i<0)
{
return max; /* i is actual number of elements */
}
else
{
if(a[i-1]>max)
{
max=a[i-1];
}
return largest( a,i-1,max);
}
}
No comments:
Post a Comment