answersLogoWhite

0

main()

{

in a,b,c,d;

printf("\n enter any four numbers");

scanf("%d%d%d%d",&a,&b,&c,&d);

if(a==ba==cb==cb==dc==d)

printf("\n numbers must be different");

else

{

if(a>b&&a>c&&a>b)

X=b>c&&b>d?b;c>d?c:d;

else if(b>c&&b>d)

x=a>c&&a>b?a:c<d?c:d;

else if(c>d)

x=a>b&&a>d?a:b>d?b:d;

else

x=a>b&&a>c?a:b>c?b:c;

printf("\n %d is second max vaalue",x);

{

}

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
JudyJudy
Simplicity is my specialty.
Chat with Judy
More answers

I will just write the function - the header stuff is easy.

int largest (int numbers[], int n)

{

int i;

int biggest=numbers[0]; /* First assign the first number to the biggest */

for (i=1; i<n; i++) /* we loop through from the 2nd element to the last */

{

if (numbers[i] > biggest) /* if we find one larger then we make it biggest */

biggest = numbers[i];

}

return biggest; /* Note: this may or may not work, you see biggest is defined ONLY for the function if you try to send it outside of the function it may not work (depending on the compiler). I put this here because it helps explain the program BEST! However, you may need to use a static variable or a global variable. */

}

User Avatar

Wiki User

15y ago
User Avatar

#include<stdio.h>

#include<conio.h>

void main()

{

int i, n, a, b, num;

a = b = 0;

clrscr();

printf("Enter the Maximum amount of Numbers :: ");

scanf("%d", &n);

for(i=0; i<n; i++)

{

printf("\nEnter the Number :: ");

scanf("%d", &num);

if (num > a)

{

b = a;

a = num;

}

else if (num > b)

b = num;

}

printf("\n\n Second Highest Number is :: %d",b);

getch();

}

User Avatar

Wiki User

12y ago
User Avatar

void main()

{

int i,k;

int a[5];

for(j=0;j<5;j++)

{

a[j]=j;

}

for(i=0;i<1;i++)

{

if(a[i]<a[i+1])

{

k=a[i];

a[i]=a[i+1];

a[i+1]=k;

}

}

printf("%d",a[1]);

}

User Avatar

Wiki User

14y ago
User Avatar

In order to find the second largest you first need to find the largest. The following program demonstrates one such method using an array of doubles. An alternative method is to sort the numbers in descending order then look for the first value that is not equal to the first number, however sorting will add an unnecessary and expensive overhead.

#include<stdio.h>

#include<float.h>

const double lowest = -DBL_MAX;

double find_largest (double* a, const unsigned size) {

if (size<1) return lowest;

double largest = a[0];

unsigned i = 0;

while (++i<size) {

if (largest<a[i])

largest = a[i];

}

return largest;

}

double find_second_largest (double* a, const unsigned size) {

if (size<2) return lowest;

const double largest = find_largest (a, size);

double second = lowest;

unsigned i = 0;

while (++i<size) {

if (a[i]<largest && second<a[i])

second = a[i];

}

return second;

}

int main (void) {

double a[10];

a[0] = 0.5;

a[1] = 0.7;

a[2] = 0.1;

a[3] = 0.9;

a[4] = 0.6;

a[5] = 0.4;

a[6] = 0.2;

a[7] = 0.8;

a[8] = 0.3;

a[9] = 0.0;

double x = find_second_largest (a, 10);

if (x==lowest) {

/* error! */

}

printf ("%f is the second largest\n", x);

return 0;

}

User Avatar

Wiki User

9y ago
User Avatar

#include<stdio.h>

#include<conio.h>

main()

{

int a[100];

int i,n,slargest,largest,ssmallest,smallest;

printf("enter the number of elements");

scanf("%d",&n);

printf("\nenter the array elements");

for(i=0;i<n;i++)

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

if(a[0]>a[1])

{

largest=a[0];

slargest=a[1];

}

else

{

largest=a[1];

slargest=a[0];

}

for(i=2;i<n;i++)

if(a[i]>largest)

{

slargest=largest;

largest=a[i];

}

else

if(a[i]>slargest)

slargest=a[i];

if(a[0]<a[1])

{

smallest=a[0];

ssmallest=a[1];

}

else

{

smallest=a[1];

ssmallest=a[0];

}

for(i=2;i<n;i++)

if(a[i]<smallest)

{

ssmallest=smallest;

smallest=a[i];

}

else

if(a[i]<ssmallest)

ssmallest=a[i];

printf("\n second largest element=%d",slargest);

printf("\n second smallest element =%d",ssmallest);

getch();

}

User Avatar

Wiki User

14y ago
User Avatar

You would use a comparison expression across multiple numbers, keeping track of the largest number and comparing it with each number supplied. To do this with a function, supply the function with an array of numbers as well as the number of elements in an array.

Then loop through the array. Keeping track of which number is largest, compare each element in the array with the largest number. If the element's value is larger than the currently stored number, store that element's number as the current number.

Once the loop is finished, simply return the largest number in the array. If no numbers have been supplied, you can return 0 or -1, assuming they are not expected to be in the array.

Find below a collection of related links containing tutorials and quick references that'll help you out immeasurably with C!

User Avatar

Wiki User

12y ago
User Avatar

146..4 is the second largest digit from a no

User Avatar

Wiki User

12y ago
User Avatar

Add your answer:

Earn +20 pts
Q: C program to find the second highest number from a set of numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the pseudo code for a program that finds the product of two numbers?

int x; //first number int y; //second number int z = x*y;


A c program for multiplication of two integers a and b?

/*PROGRAM TO ACCEPT TWO NUMBERS FROM THE USER AND PRINT THEIR MULTIPLICATION. */ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int a, b, c; // Declaration of Variables. Variables 'a' &amp; 'b' to hold first &amp; second number. And 'c' to hold result. clrscr(); // To clear the output screen every time program is executed. printf("\n Enter the first number : "); scanf("%d", &amp;a); // To accept the first number. printf("\n Enter the second number : "); scanf("%d", &amp;b); // To accept the second number. c = a*b; // Logic to get the product of the entered two numbers. printf("\n Multiplication of %d &amp; %d = %d", a, b, c); // Displaying result. getch(); // To hold the output screen. }


Biggest of three numbers using ternary operator in java?

// largest = largest of a, b, c public class largest { public static void main(String args[]) { int a,b,c,largest; a=0; b=0; c=0; a=Integer.parseInt(args[0]); b=Integer.parseInt(args[1]); c=Integer.parseInt(args[2]); largest=a&gt;b?(a&gt;c?a:c):(b&gt;c?b:c); System.out.println("The largest no. of "+a+","+b+"and"+c+"is"+largest); } }


What is the flow chart for a program that finds two product numbers?

Since all decent programming languages have the multiplication operator, you simply multiply them. If you want to go into a bit more detail, it would be a bit like this: Ask user for number "a" Ask user for number "b" Calculate result = a * b Show result (End) Use the appropriate flow chart symbols for input, etc.


How do you make a vbs script with numpad numbers?

The VBScript/Visual BASIC Script programming language uses both letters/numbers to create programs with. So, I'm not exactly sure what you mean by making a VBScript which uses only numbers, alone...? As the 'numpad' is made up of just numbers. You need to explain yourself a little bit better, I'm afraid. Did you mean, use VBScript to create a 'calculator program' with, possibly? Anyway, here is a simple VBScript calculator program... num1=CInt(InputBox("Enter the first number: ", "PROGRAM: Add 2 numbers")) num2=CInt(InputBox("Enter the second number: ", "PROGRAM: Add 2 numbers")) MsgBox("The answer is: " &amp; num1+num2) Type the above code into Windows Notepad; then, save it as... add2num.vbs ...go and find the file you just saved; and, left double click on it to make the program RUN/execute. When the program runs you should see... 1. Enter the 1st number: (you can use the NumPad to type in a number) 2. Enter the 2nd number: (you can use the NumPad to type in a next number) 3. Finally, you should see a Windows standard message box appear with the sum total result of the two numbers which you did previously type in. To do other sums...then, you can modify this simple calculator using... + ...plus sign - ...minus sign * ...multiplication sign / ...division sign