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

Answer Posted / dinesh

#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 ?    11 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

writ a program to compare using strcmp VIVA and viva with its output.

1758


What is scanf () in c?

825


Write a C program to count the number of email on text

1627


What are data structures in c and how to use them?

883


Explain a pre-processor and its advantages.

829


Why is c not oop?

722


What is indirection? How many levels of pointers can you have?

897


Why is it usually a bad idea to use gets()? Suggest a workaround.

1331


Write a program to print numbers from 1 to 100 without using loop in c?

841


What is bash c?

749


What is struct node in c?

792


You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

2045


Explain what does it mean when a pointer is used in an if statement?

818


Explain the difference between structs and unions in c?

758


What is binary tree in c?

825