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

Answer Posted / n.sankeerthan

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
int a[50],large,small;
printf("\n size of an array:"):
scanf("%d",&n);
printf("\n %d",n);
printf("\n array elements:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
printf("\n %5d",a[i]);
printf("\n"); /*initialization*/
large=a[10];
small=a[10] /*large & smallest elements*/
for(i=0;i<n;i++)
{
if(a[i]>large)
large=a[i];
else if(a[i]<small)
small=a[i];
}
printf("\n largest element is %3d",large);
printf("\n smallest element is %3d",small);
getch();
}

Is This Answer Correct ?    15 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are the different file extensions involved when programming in c?

822


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

2065


Explain what are multidimensional arrays?

789


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.

811


Why is not a pointer null after calling free?

762






What is keyword in c?

775


What is build process in c?

841


What does main () mean in c?

838


How can you tell whether a program was compiled using c versus c++?

813


Can a local variable be volatile in c?

751


What is identifier in c?

744


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

773


When should the volatile modifier be used?

869


Why is c called c?

770


What is the role of && operator in a program code?

776