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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When should a type cast not be used?

629


Explain how can you check to see whether a symbol is defined?

665


Is fortran faster than c?

587


What is dangling pointer in c?

629


What is the difference between #include and #include 'file' ?

610






How can I recover the file name given an open stream or file descriptor?

600


What are the types of data structures in c?

606


Is a house a shell structure?

701


What are reserved words with a programming language?

608


Explain the red-black trees?

611


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

663


What is typedf?

674


What is output redirection?

699


What is mean by data types in c?

557


What is a memory leak? How to avoid it?

581