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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between null pointer and void pointer.

677


What is a union?

615


what is the structure pointer?

1648


Is using exit() the same as using return?

684


What is the difference between scanf and fscanf?

671






Explain what is #line used for?

611


Ow can I insert or delete a line (or record) in the middle of a file?

579


Explain what is the difference between the expression '++a' and 'a++'?

629


What is the general form of #line preprocessor?

592


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

660


What language is lisp written in?

626


If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?

782


Can the curly brackets { } be used to enclose a single line of code?

719


What kind of structure is a house?

562


What extern c means?

547