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

What is openmp in c?

605


Can 'this' pointer by used in the constructor?

608


Describe how arrays can be passed to a user defined function

774


Why malloc is faster than calloc?

584


Can we add pointers together?

608






How can you access memory located at a certain address?

661


When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd

637


Without Computer networks, Computers will be half the use. Comment.

1865


Write a program to check prime number in c programming?

590


What are the differences between Structures and Arrays?

601


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

1491


What is this pointer in c plus plus?

586


How can you avoid including a header more than once?

555


how to make a scientific calculater ?

1555


Can include files be nested? How many levels deep can include files be nested?

650