Write a program to find the smallest and largest element in
a given array in c language

Answers were Sorted based on User's Feedback



Write a program to find the smallest and largest element in a given array in c language..

Answer / rajesh kumar s

int main()
{
int a[20],min,max;
int n;
printf("enter the num of elements\t:");
scanf("%d",&n);

printf("enter the elements\n");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0)
{
min=max=a[i];

}
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
printf("Biggest element is %d and Smallest element
is %d ",max,min);
}

Is This Answer Correct ?    234 Yes 67 No

Write a program to find the smallest and largest element in a given array in c language..

Answer / puspendu adak

#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
int i,arrb,arrl,arr[20],num;
printf("enter the number of elements");
scanf("%d",&num);
printf("enter the elements");
for(i=0;i<num;i++)
scanf("%d",&arr[i]);
arrl=arrb=arr[0];
for(i=0;i<num;i++)
{if(arr[i]>=arrb)
arrb=arr[i];
}
for(i=0;i<num;i++)
{if(arr[i]<arrl)
arrl=arr[i];
}
printf("the smallest number is %d.\nthe biggest number is
%d.",arrl,arrb);
getch();
}

Is This Answer Correct ?    27 Yes 22 No

Write a program to find the smallest and largest element in a given array in c language..

Answer / chandrashekhar

# include<stdio.h>

void main()
{
int a[10];
int max=0,min=0,n,i=0;

printf("enter array size");
scanf("%d",&n);

printf("enter elements");
for( i=0;i<n;i++)
{

scanf("%d",&a[i]);
}

//mini num
min=a[i];
for(int i=1;i<n;i++)
{

if(min>a[i])
{
min=a[i++];
}
}

//max num
max=a[i];
for(int i=1;i<n;i++)
{

if(max<a[i])
{
max=a[i++];
}
}

printf( "min=%d max=%d",min,max);
getch();
}

Is This Answer Correct ?    21 Yes 17 No

Write a program to find the smallest and largest element in a given array in c language..

Answer / alive

#include <stdio.h>
#include <conio.h>
int main()
{
int a[20],min,max;
int n,i;
printf("enter the num of elements\t:");
scanf("%d",&n);

printf("enter the elements\n");
for( i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0)
{
min=max=a[i];

}
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
printf("Biggest element is %d and Smallest element is %d ",max,min);
getch();
}

Is This Answer Correct ?    15 Yes 13 No

Write a program to find the smallest and largest element in a given array in c language..

Answer / dinesh

#include <stdio.h>
int main()
{
int a[20],min,max;
int n,i;
printf("enter the num of elements\t:");
scanf("%d",&n);

printf("enter the elements\n");
for( i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0)
{
min=max=a[i];

}
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
printf("Biggest element is %d and Smallest element
is %d ",max,min);
}

Is This Answer Correct ?    11 Yes 9 No

Write a program to find the smallest and largest element in a given array in c language..

Answer / anudeep

#include <stdio.h>
#include <conio.h>
int main()
{
int a[20],min,max;
int n,i;
printf("enter the num of elements\t");
scanf("%d",&n);

printf("enter the elements\n");
for( i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0)
{
min=max=a[i];

}
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
printf("Biggest element is %d and Smallest element is %d ",max,min);
getch();
}

Is This Answer Correct ?    3 Yes 2 No

Write a program to find the smallest and largest element in a given array in c language..

Answer / 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

Write a program to find the smallest and largest element in a given array in c language..

Answer / anudeep

#include <stdio.h>
int main()
{
int a[20],min,max;
int n,i;
printf("enter the num of elements\t:");
scanf("%d",&n);

printf("enter the elements\n");
for( i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0)
{
min=max=a[i];

}
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
printf("Biggest element is %d and Smallest element
is %d ",max,min);

Is This Answer Correct ?    3 Yes 6 No

Write a program to find the smallest and largest element in a given array in c language..

Answer / dally

#include<stdio.h>
int main()
{
int a[]= {4,3,6,7};
int l.n = 0;
int s.n = 9;
int i=0;
while(a[i] != '\0')
{
if(a[i]>= l.n)
l.n = a[i];
else if(a[i]<=s.n)
s.n = a[i]
i++;
}
printf("%d %d",s.n,l.n) ;

}

Is This Answer Correct ?    45 Yes 51 No

Write a program to find the smallest and largest element in a given array in c language..

Answer / harish

with respect to solution posted by "Hari Prasad Perabattula"

if(n%2) {
if(arr[2] < min)
min = arr[2];
if(arr[2] > max)
max = arr[2];
start = 3;
}

must be changed as

if(n%2) {
if(arr[2] < tmin)
tmin = arr[2];
if(arr[2] > tmax)
tmax = arr[2];
start = 3;
}

bcos if the 3 element in the array is the smallest then we
ignore that once we enter the for loop if min and max are
updated.

Is This Answer Correct ?    15 Yes 26 No

Post New Answer

More C Interview Questions

Define circular linked list.

0 Answers  


what is difference between array and structure?

44 Answers   College School Exams Tests, CTS, Google, HCL, IBM, Motorola, TCS,


write a program that uses point of sale system. which are mainly used by retail markets, where the is a database inventory list, a slip should be printed for the customer. manage should be able to access what has been sold and what is left from stock?

1 Answers  


Write a program in c to print 1 121 12321 1234321 123454321

11 Answers   ANR, College School Exams Tests, Mu Sigma, Wipro,


Does c have function or method?

0 Answers  






What is the purpose of scanf() and printf() functions?

0 Answers  


Can i use “int” data type to store the value 32768? Why?

0 Answers  


What is the difference between struct and typedef struct in c?

0 Answers  


Explain function?

0 Answers  


You have an array of n integers, randomly ordered with value 1 to n-1.The array is such that there is only one and one value occurred twice. How will you find this number?

1 Answers  


simple program of graphics and their output display

0 Answers   Elysium,


output for following code??? main() { int x=2,y,z; x*=3+2; printf("1.%d\n",x); x*=y=z=4; printf("2.%d %d %d\n",x,y,z); x=y==z; printf("3.%d\n",x); x==(y=z); printf("%d",x); }

2 Answers   Elysium,


Categories