Write a program to find the smallest and largest element in
a given array in c language

Answer Posted / rajesh kumar s

int main()
{
int a[20],min,max;
int n;
printf("enter the num of elements\t:");
scanf("%d",&n);

printf("enter the elements\n");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0)
{
min=max=a[i];

}
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
printf("Biggest element is %d and Smallest element
is %d ",max,min);
}

Is This Answer Correct ?    234 Yes 67 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how do you search data in a data file using random access method?

689


What are the two types of functions in c?

560


What is a double c?

584


How is a structure member accessed?

581


What is a 'null pointer assignment' error?

720






how to write a c program to print list of fruits in alpabetical order?

1784


Write a program to print "hello world" without using a semicolon?

589


Why & is used in c?

709


write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.

14951


How to compare array with pointer in c?

615


Read the following data in two different files File A: aaaaaaaadddddddd bbbbbbbbeeeeeeee ccccccccffffffff File B: 11111111 22222222 33333333 By using the above files print the following output or write it in the Other file as follows aaaaaaaa11111111dddddddd bbbbbbbb22222222eeeeeeee cccccccc33333333ffffffffffff

2234


What do you mean by a local block?

625


C language questions for civil engineering

1235


Give differences between - new and malloc() , delete and free() ?

603


C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions

606