Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

write a program to fined second smallest and largest element
in a given series of elements (without sorting)

Answers were Sorted based on User's Feedback

write a program to fined second smallest and largest element in a given series of elements (without..

/*No doubt this works fine, execute and see*/
#include<stdio.h>
#include<conio.h>

void main()
{ int size,a[100],i,j=0,k=0,min1,min2,max1,max2;
printf("Input size of an array\n");
scanf("%d",&size);
printf("Input the %d elements of the array\n",size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);

min1=a[0];
max1=a[0];
for(i=0;i<size;i++)
{
if(a[i]<min1)
{
min1=a[i];
j=i;
}
if(a[i]>max1)
{
max1=a[i];
k=i;
}
}
for(i=0;i<size;i++)
{
if(i!=j)
{
min2=a[i];
break;
}
}
for(i=0;i<size;i++)
{
if(i!=k)
{
max2=a[i];
break;
}
}
for(i=0;i<size;i++)
{
if((i!=j)&&a[i]<min2)
{
min2=a[i];
}
if((i!=k)&&a[i]>max2)
{
max2=a[i];
}
}
printf("Second minimal element of the array is %d\n",min2);
printf("Second maximal element of the array is %d\n",max2);

getch();

}

 Is This Answer Correct ? 13 Yes 4 No

write a program to fined second smallest and largest element in a given series of elements (without..

#include<stdio.h>
#include<conio.h>

int main()
{
int size,a[100],i,j=0,k=0,min1,min2;
printf("Input size of an array\n");
scanf("%d",&size);
printf("Input the %d elements of the array\n",size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);

min1=a[0];
for(i=0;i<size;i++)
{
if(a[i]<min1)
{
min1=a[i];
j=i;
}

}
for(i=0;i<size;i++)
{
if(i!=j)
{
min2=a[i];
break;
}
}

for(i=0;i<size;i++)
{
if((i!=j)&&a[i]<min2)
{
min2=a[i];
}

}
printf("Second minimam element of the array is %d\n",min2);

getch();

}

 Is This Answer Correct ? 5 Yes 1 No

write a program to fined second smallest and largest element in a given series of elements (without..

void main()
{
int a[12],max,min1.min2,max2,i,temp;
printf("enter valu");
for(i=0;i<11;i++)
scanf(%d,&a[i]);
max=a[0];
min1=a[0];
for(i=1;i<11;i++)
{
if(max<a[i])
max=a[i];
if(min1>a[i];
min1=a[i]
}
for(i=1;i<11;i++0
{
if((max2>a[i])&&(max2!=max){
max2=a[i];
}
if((min2<a[i])&&(min2!=min1))
{
min2=a[i];}

print("small is %d and large is %d", min2,max2);
}

 Is This Answer Correct ? 15 Yes 13 No

write a program to fined second smallest and largest element in a given series of elements (without..

#include <stdio.h>

void main()
{
int i, ar[] ={15,22,122,15,6,12};
int a,b= 0,c,ta ,tb, tc;
a =ar[0];
b = ar[1];

for (i = 0; i < 6 ;i++)
{
if(a > ar[i])
{
b = a;
a = ar[i];
}
else if(b > ar[i])
{
b = ar[i];
}
}

printf("\n %d ",b);
}

 Is This Answer Correct ? 3 Yes 3 No

write a program to fined second smallest and largest element in a given series of elements (without..

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{

Console.WriteLine("Enter Array Length.");
int ArrayLength =
int[] arr = new int[ArrayLength];

Console.WriteLine("\nEnter Array Elements");
for (int i = 0; i < arr.Length; i++)
{
}

Console.WriteLine("\nElements are :- ");
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(arr[i]);
}

int Largest = arr[0], SecondLargest = arr[0],
Smallest = arr[0], SecondSmallest = arr[0];
for (int j = 1; j < arr.Length; j++)
{
if (Smallest > arr[j])
{
Smallest = arr[j];
}

if (Largest < arr[j])
{
Largest = arr[j];
}
}

for (int j = 1; j < arr.Length; j++)
{
int value = arr[j];

if (arr[j] < SecondSmallest && arr[j] !=
Smallest)
{
SecondSmallest = arr[j];
}

if (SecondLargest < arr[j] && arr[j] < Largest)
{
SecondLargest = arr[j];
}
}

Console.WriteLine("Largest : " + Largest);
Console.WriteLine("Second Largest : " +
SecondLargest);
Console.WriteLine("Smallest : " + Smallest);
Console.WriteLine("Second Smallest : " +
SecondSmallest);

}

 Is This Answer Correct ? 3 Yes 4 No

write a program to fined second smallest and largest element in a given series of elements (without..

void main()
{
int a[12],max,min,min2,i;
printf("enter values");
for(i=0;i<10;i++)
scanf(%d,&a[i]);
max=a[0];
min=a[0];
for(i=0;i<10;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
min2=a[0];
for(i=0;i<10;i++)
{
if(min2>a[i] && a[i]!=min)
{
min2=a[i];
}
printf("The second smallest element is:-%d",min2);
printf("The largest element is:-%d",max);
getch();
}

 Is This Answer Correct ? 2 Yes 4 No

write a program to fined second smallest and largest element in a given series of elements (without..

#include<stdio.h>

void main()
{
int a[10] = {5,4,1,7,3,0,8,23,12,24};
int Lcount = 0, Gcount = 0, i, j;

for(i = 0; i<10; i++)
{
Gcount = 0;
Lcount = 0;
for(j = 0; j<10; j++)
{
if(a[i] > a[j])
{
Gcount++;
Lcount++;
}
}
if(Gcount == 8)
{
printf("The second largest no is: %
d \n", a[i]);
}
if(Lcount == 1)
{
printf("The second smallest no is: %
d \n", a[i]);
}
}
_getch();
}

 Is This Answer Correct ? 2 Yes 4 No

write a program to fined second smallest and largest element in a given series of elements (without..

include<stdio.h>
#include<conio.h>
void main()
{
int a[10],max,min,i,temp;
printf("\n enter array element");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
//second smallest number
min=a[0];
for(i=0;i<10;i++)
{
if(min>a[i])
{
min=a[i];
}

 Is This Answer Correct ? 4 Yes 12 No

write a program to fined second smallest and largest element in a given series of elements (without..

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],max,min,i,temp;
printf("\n enter array element");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
//second smallest number
min=a[0];
for(i=0;i<10;i++)
{
if(min>a[i])
{
min=a[i];
}

 Is This Answer Correct ? 20 Yes 39 No

More C Interview Questions

What is encapsulation?

how do u find out the number of 1's in the binary representation of a decimal number without converting it into binary(i mean without dividing by 2 and finding out the remainder)? three lines of c code s there it seems...can anyone help

we all know about the function overloading concept used in C++ and we all learnt abt that.... but that concept is already came in C in a very smaller propotion ... my question is IN WHICH CONCEPT THERE IS A USE OF FUNCTION OVERLOADING IS USED in C language?????????????

What is a lookup table in c?

Can you assign a different address to an array tag?

Function shall sum members of given one-dimensional array. However, it should sum only members whose number of ones in the binary representation is higher than defined threshold (e.g. if the threshold is 4, number 255 will be counted and 15 will not) - The array length is arbitrary - output the results to the stdout

If one always ought to act so as to produce the best possible circumstances, then morality is extremely demanding. No one could plausibly claim to have met the requirements of this "simple principle." . . . It would seem strange to punish those intending to do good by sentencing them to an impossible task. Also, if the standards of right conduct are as extreme as they seem, then they will preclude the personal projects that humans find most fulfilling. From an analytic perspective, the potential extreme demands of morality are not a "problem." A theory of morality is no less valid simply because it asks great sacrifices. In fact, it is difficult to imagine what kind of constraints could be put on our ethical projects. Shouldn't we reflect on our base prejudices, and not allow them to provide boundaries for our moral reasoning? Thus, it is tempting to simply dismiss the objections to the simple principle. However, in Demands of Morality, Liam Murphy takes these objections seriously for at least two distinct reasons. First, discussion of the simple principle provides an excellent vehicle for a discussion of morality in general. Perhaps, in a way, this is Murphy's attempt at doing philosophy "from the inside out.". . . Second, Murphy's starting point tells us about the nature of his project. Murphy must take seriously the collisions between moral philosophy and our intuitive sense of right and wrong. He [must do so] because his work is best interpreted as intended to forge moral principles from our firm beliefs, and not to proscribe beliefs given a set of moral principles. [Murphy] argues from our considered judgments rather than to them. . . For example, Murphy cites our "simple but firmly held" beliefs as supporting the potency of the over-demandingness objection, and nowhere in the work can one find a source of moral values divorced from human preferences. Murphy does not tell us what set of "firm beliefs" we ought to have. Rather, he speaks to an audience of well-intentioned but unorganized moral realists, and tries to give them principles that represent their considered moral judgments. Murphy starts with this base sense of right and wrong, but recognizes that it needs to be supplemented by reason where our intuitions are confused or conflicting. Perhaps Murphy is looking for the best interpretation of our convictions, the same way certain legal scholars try to find the best interpretation of our Constitution. This approach has disadvantages. Primarily, Murphy's arguments, even if successful, do not provide the kind of motivating force for which moral philosophy has traditionally searched. His work assumes and argues in terms of an inner sense of morality, and his project seeks to deepen that sense. Of course, it is quite possible that the moral viewpoints of humans will not converge, and some humans have no moral sense at all. Thus, it is very easy for the moral skeptic to point out a lack of justification and ignore the entire work. On the other hand, Murphy's choice of a starting point avoids many of the problems of moral philosophy. Justifying the content of moral principles and granting a motivating force to those principles is an extraordinary task. It would be unrealistic to expect all discussions of moral philosophy to derive such justifications. Projects that attempt such a derivation have value, but they are hard pressed to produce logical consequences for everyday life. In the end, Murphy's strategy may have more practical effect than its first-principle counterparts, which do not seem any more likely to convince those that would reject Murphy's premises. 1) The author suggests that the application of Murphy's philosophy to the situations of two different groups: a) would help to solve the problems of one group but not of the other. b) could result in the derivation of two radically different moral principles. c) would be contingent on the two groups sharing the same fundamental beliefs. d) could reconcile any differences between the two groups. 2) Suppose an individual who firmly believes in keeping promises has promised to return a weapon to a person she knows to be extremely dangerous. According to Murphy, which of the following, if true, would WEAKEN the notion that she should return the weapon? a) She also firmly believes that it is morally wrong to assist in any way in a potentially violent act. b) She believes herself to be well-intentioned in matters of right and wrong. c) The belief that one should keep promises is shared by most members of her community. d) She derived her moral beliefs from first-principle ethical philosophy. 3) The passage implies that a moral principle derived from applying Murphy's philosophy to a particular group would be applicable to another group if: a) the first group recommended the principle to the second group. b) the moral viewpoints of the two groups do not converge. c) the members of the second group have no firmly held beliefs. d) the second group shares the same fundamental beliefs as the first group. 4) According to the passage, the existence of individuals who entirely lack a moral sense: a) confirms the notion that moral principles should be derived from the considered judgments of individuals. b) suggests a potential disadvantage of Murphy's philosophical approach. c) supports Murphy's belief that reason is necessary in cases in which intuitions are conflicting or confused. d) proves that first-principle strategies of ethical theorizing will have no more influence over the behavior of individuals than will Murphy's philosophical approach. 5) Which of the following can be inferred about "doing philosophy from the inside out?" a) Murphy was the first philosopher to employ such an approach. b) It allows no place for rational argument in the formation of ethical principles. c) It is fundamentally different from the practice of first-principle philosophy. d) It is designed to dismiss objections to the "simple principle." 6) A school board is debating whether or not to institute a dress code for the school's students. According to Murphy, the best way to come to an ethical decision would be to: a) consult the fundamental beliefs of the board members. b) analyze the results of dress codes instituted at other schools. c) survey the students as to whether or not they would prefer a dress code. d) determine whether or note a dress code has ever been instituted in the school's history

How can this be legal c?

#include<stdio.h> int main() { int a[3][3][2]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}; printf("%d\n",*(*(*a+1)); return 0; } What will be the output of the above question? And how?

Write a c program to print the sizes and ranges of different data types in c?

What is c programing language?

What is #line used for?

Categories