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
When should I declare a function?
Is it acceptable to declare/define a variable in a c header?
How does #define work?
What is the newline escape sequence?
I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.
Can you write a programmer for FACTORIAL using recursion?
Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58
Can you please explain the difference between exit() and _exit() function?
Is c still relevant?
If I have a char * variable pointing to the name of a function ..
Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above
Does sprintf put null character?
if p is a string contained in a string?
What is the use of getch ()?
how to count no of words,characters,lines in a paragraph.