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
Did c have any year 2000 problems?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)
What is the most efficient way to count the number of bits which are set in an integer?
What is an array in c?
What is the advantage of an array over individual variables?
What is a pointer value and address in c?
Is stack a keyword in c?
Explain how do you declare an array that will hold more than 64kb of data?
Explain can the sizeof operator be used to tell the size of an array passed to a function?
write a program in c language to print your bio-data on the screen by using functions.
How can you allocate arrays or structures bigger than 64K?
Explain how can type-insensitive macros be created?
Why doesnt this code work?
Why n++ execute faster than n+1 ?
Can we change the value of constant variable in c?