Find The Minimum Number In An Array Using Recursion | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

So when the function calls itself does it go through the whole function or goes back from where it was called and doesn't read the lines after that like in your case possible_min = min(array[ ], n-1).
So when the function calls itself from main this is the line after the base case so when it reaches this point does it go back and calls itself again until n==1 or it still goes down to the body and compares and then calls itself. I am trying to understand recursion by dry running but it is confusing to me how recursion works. I would greatly appreciate if you could explain a little.

awabkhan
Автор

Thank you so much sharing your knowledge
I have wired program can you pls tell me why the output is 11 here the program

#include <stdio.h>
int main(void)
{
int arr[2][3] = {{3, 2, 1}, {8, 9, 10}};
int **p= arr;
for (int i = 0; i < 2; i++)
{
printf("%d ", *p + 2);
printf("\n");
}
return 0;
}
Sorry if my question bothered you because I am playing with memory address and also practicing the pointer concepts like double pointer by watching your videos .... Can you pls explain this one .
Thank you..

ramakrishna
Автор

Just ran it through the Visual Studio debugger... So for every call on the stack is the value of n saved in the activation record?

Geo
Автор

#include <stdio.h>
int n, arr[50];

int minimum(int n, int arr[]){
if(n==1)
return arr[n-1];
int min= minimum(n-1, arr);
if(min<arr[n-1])
return min;
else
return arr[n-1];

}
int main() {
int max, min;
printf("Enter size of array : ");
scanf("%d", &n);

printf("Enter element of array : ");

for(int i=0;i<n;i++){
scanf("%d", &arr[i]);
}
minimum(n, arr);
printf("minimum value is : %d ", minimum(n, arr));

return 0;
}

Swayam_course