C program to find the min and max of given numbers without using array
kw.c
#include<stdio.h>intmain(){inti,n,num,min,max=0;printf("———————————————————————————————————————————");printf("\nProgram to find the min/max of given numbers");printf("\n———————————————————————————————————————————");printf("\nHow many numbers you want to enter ");scanf("%d",&n);printf("\nEnter %d numbers\n",n);scanf("%d",&num);min=num;if(num>=max)max=num;for(i=1;i<n;i++){scanf("%d",&num);if(num>max)max=num;if(num<min)min=num;}printf("\nMaximum number %d",max);printf("\nMinimum number %d",min);printf("\n———————————————————————————————————————————\n");return0;}
Output
kodingwindow@kw:~$ gcc kw.c kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to find the min/max of given numbers
———————————————————————————————————————————
How many numbers you want to enter 5
Enter 5 numbers
-10
50
1005
2048
155
Maximum number 2048
Minimum number -10
———————————————————————————————————————————
kodingwindow@kw:~$
C program to find the min and max of given numbers using array
kw.c
#include<stdio.h>
#define N 10
intmain(){inta[N],max,min;printf("———————————————————————————————————————————");printf("\nProgram to find the min/max of given numbers");printf("\n———————————————————————————————————————————");printf("\nEnter %d numbers\n",N);for(inti=0;i<N;i++){scanf("%d",&a[i]);}max=a[0];min=max;for(inti=0;i<N;i++){if(a[i]>max)max=a[i];if(a[i]<min)min=a[i];}printf("\nMaximum number %d",max);printf("\nMinimum number %d",min);printf("\n———————————————————————————————————————————\n");return0;}
Output
kodingwindow@kw:~$ gcc kw.c kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to find the min/max of given numbers
———————————————————————————————————————————
Enter 10 numbers
5
-25
-5005
1024
2048
155
233
65535
625
1225
Maximum number 65535
Minimum number -5005
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the KodingWindow Android app. We intend to soon make it available on the Google Play Store. Currently, you need to install apk manually. Would you like to get the app? Minimum Requirement(s): Android 10