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

in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.

7774


What is union in c?

844


Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.

852


Can static variables be declared in a header file?

816


What is volatile variable in c?

858


please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com

1562


How are strings stored in c?

791


Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

835


Can a variable be both const and volatile?

882


Write a program to swap two numbers without using third variable?

1046


When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.

1760


Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix

1756


Explain what is the benefit of using enum to declare a constant?

814


Why do we use main function?

905


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1716