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

Answer Posted / chandrashekhar

# include<stdio.h>

void main()
{
int a[10];
int max=0,min=0,n,i=0;

printf("enter array size");
scanf("%d",&n);

printf("enter elements");
for( i=0;i<n;i++)
{

scanf("%d",&a[i]);
}

//mini num
min=a[i];
for(int i=1;i<n;i++)
{

if(min>a[i])
{
min=a[i++];
}
}

//max num
max=a[i];
for(int i=1;i<n;i++)
{

if(max<a[i])
{
max=a[i++];
}
}

printf( "min=%d max=%d",min,max);
getch();
}

Is This Answer Correct ?    21 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what standard functions are available to manipulate strings?

796


The file stdio.h, what does it contain?

854


Why is structure important for a child?

814


write a program to copy the string using switch case?

2593


 write a program that will open the file, count the number of occurences of each word in the the complete works of shakespeare.  You will then tabulate this information in another file.

1929


Implement bit Array in C.

867


What is return in c programming?

696


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

1684


What are the usage of pointer in c?

889


What is pass by value in c?

758


What does do in c?

774


What is atoi and atof in c?

788


What is call by reference in functions?

852


What is data types?

792


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

1898