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

Answer Posted / alive

#include <stdio.h>
#include <conio.h>
int main()
{
int a[20],min,max;
int n,i;
printf("enter the num of elements\t:");
scanf("%d",&n);

printf("enter the elements\n");
for( 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);
getch();
}

Is This Answer Correct ?    15 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a program to find factorial of a number using recursive function.

650


What is difference between scanf and gets?

618


p*=(++q)++*--p when p=q=1 while(q<=6)

1272


What is this pointer in c plus plus?

600


Do array subscripts always start with zero?

788






What is New modifiers?

676


What is the value of uninitialized variable in c?

578


What is the scope of local variable in c?

582


What is the use of getchar() function?

634


Differentiate between a structure and a union.

770


Do pointers store the address of value or the actual value of a variable?

613


any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above

649


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

729


please give me some tips for the placement in the TCS.

1639


What is the value of a[3] if integer a[] = {5,4,3,2,1}?

677