Hello Friend’s
Today we learn how to find maximum and minimum number at
same time using array in c-language.
Before we started our program we need to know about what is
array ?
In simple word array is use to store more then one or many
constant in one variable
We know, if we declare one variable then we store only one
number in that variable but by using array we should store more then one or
many number or character in one variable.
In short Array is use to store multiple number in one
variable
You can apply array by placing square brackets after the
variable
Note1: whenever use array it’s compulsory to use loop.
FOR EXAMPLE :
a[5] Ã apply square after the
variable
a[5] Ã and inside the square brackets
write how many constant you declared in one variable here we declared 5
constant (now you can store five constant in one variable).
a[5]={4,7,3,8,5} Ã after declaring constant placing equal to sign and inside the curly bracket you can write particular constant. here in this example five constant is 4,7,3,8,5 .
Now I hope so you
are understand concept of array (in this program we use relational operators
too).
So now we write our program to find maximum and minimum number at same time.
SOURCE CODE:-
#include<stdio.h>int main(){ int a[5],i; printf("enter the number to find max and min value\n"); for(i=0;i<5;i++){ scanf("%d",&a[i]); } int max=a[0]; for(i=0;i<5;i++){ if(a[i]>max){ max=a[i]; } } printf("max number is %d\n",max); int min=a[0]; for(i=0;i<5;i++){ if(a[i]<min){ min=a[i]; } } printf("min number is %d",min); return 0;} OUTPUT:-
enter the number to find max and min value
34
23
12
67
45
max number is 67
min number is 12
If you like the content then share now

0 Comments