program to read 3 values,and find largest btwn the 3

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
cout<<"enter 1st number";
cin>>a;
cout<<"enter 2nd number";
cin>>b;
cout<<"enter third number";
cin>>c;
clrscr();
if(a>b)
{
if(a>c)
cout<<"the biggest number is:- "<<a;
else
cout<<"the biggest number is:- "<<c;
}
else
{
if(b>c)
cout<<"the biggest number is:- "<<b;
else
cout<<"the biggest number is:- "<<c;
}
getch();
}
Is there a question in there or are you storing code?
#include <iostream>
using namespace std;
int main ()
{

int a,b,c;

cout<<"Enter the first number: ";
cin>>a;
cout<<"Enter the second number: ";
cin>>b;
cout<<"Enter the third number: ";
cin>>c;

if (a>b && a>c) && (b>c) { cout<<a<<b<<c; }

if (a>b && a>c) && (c>b) { cout<<a<<c<<b; }

if (b>a && b>c) && (a>c) { cout<<b<<a<<c; }

if (b>a && b>c) && (c>a) { cout<<b<<c<<a; }

if (c>a && c>b) && (a>b) {cout<<c<<a<<b; }

if (c>a && c>b) && (b>a) { cout<<c<<b<<a; }


cin.get (); cin.get() ;
return 0;
}
Last edited on
My code is better.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Three numbers:
#include <vector>
#include <iostream>
#include <algorithm>

int main()
{
  std::vector <int> values;
  int num;

  std::cout << "Enter some numbers followed by end-of-file: " << std::endl;
  while (std::cin >> num)
  {
    values.push_back(num);
  }

  std::cout << "The largest value is : " << *std::max_element( values.begin(), values.end() ) << std::endl;
  return 0;
}
I've tried this before, so you do not have to worry about is not running.
Hope this helpful
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>
using namespace std;

//FUNCTION
void intswap(int &a, int &b)
{
	int temp;
	temp = a;
	a = b;
    b = temp;
}
int main()
{	
	int counter;
	int input1;
    int input2;
	int input3;
	char question[2];

	while(true){
	
	counter = 0;
	cout << ""<< ++counter <<". Please Enter the first number : ";
    cin >> input1;
	cin.sync(); //clear buffer

	cout << ""<< ++counter <<". Please Enter the second number : ";
    cin >> input2;
	cin.sync();

	cout << ""<< ++counter <<". Please Enter the third number : ";
	cin >> input3;
	cin.sync();
	
	if(input1 < input2)
		intswap(input1, input2);
	if(input1 < input3)
		intswap(input1, input3);
	else
	{
		if(input1 < input3)
			intswap(input1, input3);
	}
		

	cout << "The largest number is "<< input1 <<""<<endl<<endl;
	cout << "Try again ? [y/n] : ";
	cin  >> question;
	cout << endl;
	if(!strcmpi("n", question))
		break;
	}

	cin.get();
	return 0;       
}
Last edited on
Topic archived. No new replies allowed.