C program to find a minimum number and maximum number.

 

01  #include<stdio.h>
02
03 int main()
04 {
05 int i,n,val,min,max=0;
06 printf("Enter how many numbers you want to enter:");
07 scanf("%d",&n);
08 printf("nEnter the %d numbers:n",n);
09 scanf("%d",&val); /* Accept in the first element */
10 min=val; /* Assuming it as minimum */
11
12 if(val>=max) /* Assigning the largest value to max.*/
13 max=val;
14 for(i=1;i<n;i++) /* For-loop for remaining n-1 elements.*/
15 {
16 scanf("%d",&val); /* Only one block to find max and min simultaneously. */
17 if(val>max)
18 max=val;
19 if(val<min)
20 min=val;
21 }
22 printf("nThe maximum of given %d numbers is: %d",n,max);
23 printf("n");
24 printf("nThe minimum of given %d numbers is:%d",n,min);
25
26 return 0;
27 }
 
 OUTPUT :

Enter how many numbers you want to enter:5

Enter the 5 numbers:
12
32
44
53
1

The maximum of given 5 numbers is: 53

The minimum of given 5 numbers is:1

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.