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
What is a lookup table in c?
What is a function simple definition?
Where register variables are stored in c?
why we wont use '&' sing in aceesing the string using scanf
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
How will you find a duplicate number in a array without negating the nos ?
write a program to print data of 5 five students with structures?
Can a program have two main functions?
Which header file is essential for using strcmp function?
What are the types of c language?
Why c is faster than c++?
How do I read the arrow keys? What about function keys?
Can 'this' pointer by used in the constructor?
When was c language developed?
What is the difference between struct and typedef struct in c?