Ticker

6/recent/ticker-posts

Header Ads Widget

Contact Us For Advertisement: 9858091920

Find maximum and minimum number - C Programming Language

Tutor Chetan

C Programming Language

Question: Find maximum and minimum number providing no of inputs




/* Find maximum and minimum */ 
/* Program Coded By Chetan Thapa Magar */ 

#include<stdio.h> 
#include<conio.h> 
#include<math.h> 
int max(int a[], int, int); 
int min(int b[], int, int); 
void main() 



int i, n, a[50], big, small; 
printf("Enter how many numbers:\t");
scanf("%d", &n);
printf("\nEnter the number one by one:\n");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
big=a[0];
small=a[n-1];
printf("\nThe maximum value is %d", max(a, n, big));
printf("\nThe minimum value is %d", min(a, n, small));
getch();
}

int max(int a[], int n, int big) 
{
if(n==0)
return big;
else
n--;
if(a[n]>big)
big=a[n];
return(max(a,n,big));
}
int min(int a[], int n, int small)
{
if(n==0)
return small;
else
n--;
if(a[n]<small)
small=a[n];
return min(a, n, small);
}

Output / Execution:

Enter how many numbers: 5 
Enter the numbers one by one 

14 
56 
34 
63 
45 

The maximum value is 63 
The minimum value is 14 

Post a Comment

0 Comments