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
Why c language?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
What is the difference between exit() and _exit() function?
What are the differences between new and malloc in C?
What is keyword with example?
What is a const pointer in c?
string reverse using recursion
What is a structural principle?
What is a static variable in c?
What are the types of arrays in c?
What is the meaning of 2d in c?
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
How to write c functions that modify head pointer of a linked list?
GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)
write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.