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
Can two or more operators such as and be combined in a single line of program code?
Why ca not I do something like this?
What are run-time errors?
How can I manipulate individual bits?
What are identifiers in c?
What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?
Why is void main used?
Explain what is a program flowchart and explain how does it help in writing a program?
Explain the difference between getch() and getche() in c?
How can a process change an environment variable in its caller?
Can you please explain the difference between exit() and _exit() function?
In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational
#include