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
Explain what is the benefit of using enum to declare a constant?
Explain the difference between ++u and u++?
How can I check whether a file exists? I want to warn the user if a requested input file is missing.
Why do we need arrays in c?
How can you find the exact size of a data type in c?
Explain modulus operator. What are the restrictions of a modulus operator?
What is the difference between pure virtual function and virtual function?
What is the use of bitwise operator?
What does *p++ do? What does it point to?
.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; }
how to execute a program using if else condition and the output should enter number and the number is odd only...
How do we make a global variable accessible across files? Explain the extern keyword?
What is #line in c?
What is a void pointer in c?
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.?