answersLogoWhite

0


Best Answer

//The following is very simple program that will find the largest of any 3 numbers

#include <iostream>

using namespace std;

int main()

{

int n1, n2, n3, largest;

cout <<"Enter any 3 numbers ";

cin >>n1;

cin >>n2;

cin >>n3;

if(n1 > n2 && n1 > n3)

largest= n1;

else if(n2 >n1 && n2 >n3)

largest= n2;

else

largest= n3;

return 0;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

The most common way is to use a function that returns the max of two values, passing the result of that into the same function along with the third value. The other solution is to pass all three into a single function call. It makes no real difference which you use as inline expansion would eliminate all the function calls anyway. It's just a question of which is easier to read and understand. The single call is more complex to implement but is easier to call, while the double call is easier to implement but more complex to call. However, the double call can easily be extended to a triple call for the max of 4 numbers, and so on.

#include <iostream>

int max(int x, int y )

{

return(x>y?x:y);

}

int max(int x, int y, int z )

{

return(x>y?x>z?x:z:y>z?y:z);

}

int main()

{

int x=1, y=2, z=3;

std::cout << max(x,y,z) << std::endl;

std::cout << max(max(x,y),z) << std::endl;

return( 0 );

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

int i=0,a,b,c,d;

label:

while(i == 0){

switch(1){

case 1:

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

printf("%d is greater",a);

i++;

goto label;

}

case 2:

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

printf("%d is greater",b);

i++;

goto label;

}

case 3:

if(c>d){

printf("%d is greater",c);

i++;

goto label;

}

case 4:

printf("%d is greater",d);

i++;

goto label;

}

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include <iostream.h>

class biggest

{private:

int a,b,c,big;

public:

void getdata(void);

void bigge(void);

void putdata(void);

};

void biggest :: getdata()

{

cout<<"Enter the number"

cin>>a>>b>>c;

}

void biggest :: putdata()

{

cout<<"a="<<a;

cout<<"b="<<b;

cout<<"c="<<c;

cout<<"biggest="<<big;

}

void biggest :: bigge(void)

{

if (a<b && a<c)

{big=a;

cout<<"biggest="<<big;

}

elseif(b<a && b<c)

{

big=b;

cout<<"biggest="<<big;

}

elseif (c<a && c<b)

{big=c;

cout<<"biggest ="<<big;

}

}

int main()

{

biggest b;

b.getdata();

b.bigge();

b.putdata();

return 0:

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A program in C plus plus using switch statement To find largest number among three variables?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the number of decision variables allowed in a linear program?

There is no limit to the number of variables.


State max number of points lie on graph of linear equation in two variables to represent this statement?

There is no "this statement" associated with the question, but the maximum number of points which lie of the graph of a linear equation in two variables is infinite.


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Is a number a variable or the product of a number and one or more variables raised to whole number powers?

The statement is true only if either the number is 0, or the variables are all raised to the power 0. In no other case can a variable involved.


Write a program By using if else statement to read a number and check whether it is positive or negative?

write a c++program by using if statement to read a number and check whether it is positive or negative


How many structure variables of a given type can you use in a C program?

You can use unlimited number of variables for a structure and you can also declare array of structures.


Write a program large number and small number among n numbers by using If statement?

12


C program to fine the largest of 10 given number?

first sort the ten numbers in descending order and print the first number. That will be the largest no


Which statement is falseThe largest number of immigrants to America before 1860 came from Central and Southeastern Europe?

The largest number of immigrants to America before 1860 came from Central and Southeastern Europe.


Write a pseudocode statement that assigns the sum of 10 and 14 to the variable total?

There are different ways of writing a pseudocode statement but the concept remains, it can be presented: /*Declare variables Total (number (3)) = 0 A (number (2)) =10 B (number (2)) =14 begin Total=A+B end


What is the largest prime no that is stored in 8 bit pattern?

Write your own prime number program and find out.


How many variables do formulas have?

There is no limit to the number of variables a formula can have.