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

Answer Posted / anudeep

#include <stdio.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);

Is This Answer Correct ?    3 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of macro in C language?

848


What will be the outcome of the following conditional statement if the value of variable s is 10?

1028


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

818


Explain how do you declare an array that will hold more than 64kb of data?

1149


Describe static function with its usage?

846


Combinations of fibanocci prime series

1334


Is c still used?

784


Write a program to reverse a string.

821


Why header file is used in c?

761


An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above

914


how can f be used for both float and double arguments in printf? Are not they different types?

802


List some basic data types in c?

750


Here is a neat trick for checking whether two strings are equal

769


What does *p++ do?

786


Can variables be declared anywhere in c?

820