How to write a C Program to Find max and min in array using pointer concept in C Programming Language ?
This C Program to Find maximum and minimum in array using pointer concept.
Solution:
- /*C Program to find maximum and minimum element in array using pointer */
- #include <stdio.h>
- #include <stdlib.h>
- void max_min(int num[],int length,int *max,int *min);
- int main()
- {
- int len;
- int num[len];
- int i,max,min;
- printf("How many numbers do you wanna input ?");
- scanf("%d",&len);
- printf("Enter %d numbers to find the biggest and small (enter x to terminate)",len);
- for(i=0;i<len-1;i++)
- {
- scanf("%d",&num[i]);
- }
- max_min(num,len,&max,&min);
- printf("Biggest number :%d",max);
- printf("Smallest number :%d",min);
- system("pause");
- return 0;
- }
- void max_min(int num[],int length,int *max,int *min)
- {
- int k;
- for(k=0;k<length-1;k++)
- {
- if(num[k]>*max)
- *max=num[k];
- else if(num[k]<*min)
- *min=num[k];
- }
- }