C program to find largest and smallest number in an array





C code to find largest and smallest number in an array


#include<stdio.h>
int main(){
  int a[50],size,i,big,small;

  printf("\nEnter the size of the array: ");
  scanf("%d",&size);
  printf("\nEnter %d elements in to the array: ", size);
  for(i=0;i<size;i++)
      scanf("%d",&a[i]);

  big=a[0];
  for(i=1;i<size;i++){
      if(big<a[i])
           big=a[i];
  }
  printf("Largest element: %d",big);
 
  small=a[0];
  for(i=1;i<size;i++){
      if(small>a[i])
           small=a[i];
  }
  printf("Smallest element: %d",small);

  return 0;
}


Sample Output:
Enter the size of the array: 4
Enter 4 elements in to the array: 2 7 8 1
Largest element: 8
Smallest element: 1



Alogrithm:
**




14 comments:

Anonymous said...

what does [50] & [i] mean ? why are they in brackets ?

Anonymous said...

to declare in arrays we have to use brackets.

anonymous said...

Y do v need to ask d user for d Size. Directly entering d elements wont work?

Unknown said...

they are array and 50 represent array size and i for using loop which represent element position num....

sachin thakur said...

[50] is the size of the array.it means if we have an integer array it aqquire 100 bytes in case of [50].because an integer value took 2 bytes.and "i" is nothing ,it is just written to show the compiler that this is used in the main program....

Praveen V said...

Simple and logical. Thanks a lot :-)

Unknown said...

can anyone find smallest and largest element using bitwise opertor?

Unknown said...

thank u

Unknown said...

awsome bro.......it to easy to understand.......can i found function type problem in ur website....

Unknown said...

array is the collection of the elements

Unknown said...

tarnary oparetor:
# include

void main()
{
int a, b, c, big ;
printf("Enter three numbers : ") ;
scanf("%d %d %d", &a, &b, &c) ;
big = a > b ? (a > c ? a : c) : (b > c ? b : c) ;
printf("\nThe biggest number is : %d", big) ;
}

Unknown said...

i cannot understand what is the problem with this,?
but its donot run properly


#include >
int main()
{
int std,i,a[50],best,low;
printf("how much student : ");
scanf("%d",&std);
for(i=1;i<=std;i++)
{
printf("inter %d student mark : ",i);
scanf("%d",&a[i]);
}

best=a[0];
for(i=0;ia[i])
low=a[i];
}
printf("\nlow mark is :%d\n\n",low);
return 0;
}

Unknown said...

i cannot understand what is the problem with this,?
but its donot run properly


#include >
int main()
{
int std,i,a[50],best,low;
printf("how much student : ");
scanf("%d",&std);
for(i=1;i<=std;i++)
{
printf("inter %d student mark : ",i);
scanf("%d",&a[i]);
}

best=a[0];
for(i=0;ia[i])
low=a[i];
}
printf("\nlow mark is :%d\n\n",low);
return 0;
}

Unknown said...

F AN ARRAY OF NUMBERS IS PROVIDED, SAY 93, 64, 47, 64, 49, ARRANGE IT IN THE FORM OF A SINGLE NUMBER SUCH THAT THE CONCLUDING NUMBER IS MAXIMUM. OUTPUT EXPECTED IN OUR CASE WILL BE 9364644947. WRITE A FUNCTION TO PROVIDE THE EXPECTED OUTPUT.