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 is the benefit of using enum to declare a constant?

589


Explain the difference between ++u and u++?

641


How can I check whether a file exists? I want to warn the user if a requested input file is missing.

657


Why do we need arrays in c?

587


How can you find the exact size of a data type in c?

602






Explain modulus operator. What are the restrictions of a modulus operator?

601


What is the difference between pure virtual function and virtual function?

653


What is the use of bitwise operator?

693


What does *p++ do? What does it point to?

617


.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }

2001


how to execute a program using if else condition and the output should enter number and the number is odd only...

1660


How do we make a global variable accessible across files? Explain the extern keyword?

1423


What is #line in c?

564


What is a void pointer in c?

609


Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?

631