78.8k views
2 votes
Write an if statement that assigns to the variable biggest the Greatest value contained in variables i, j and k, Assume the three values are distinct.

User Poke
by
6.9k points

1 Answer

6 votes

Answer:

if(i > j && i > k) // check if i is greatest

{

biggest = i;

}

else if( j> i && j > k) // check j is greatest

{

biggest = j;

}

// else highest is k

else // otherwise k is greatest

{

biggest = k;

}

Step-by-step explanation:

Following are the program in c++ language

#include<iostream> // header file

using namespace std; // namespace

int main() // main function

{

int i,j,k;// varaible declaration

int biggest;

cout<<" \\enter the value i,j and k:\\ ";

cin>>i>>j>>k;

if(i > j && i > k) // check if i is greatest

{

biggest = i;

}

else if( j> i && j > k) // check j is greatest

{

biggest = j;

}

// else highest is k

else // otherwise k is greatest

{

biggest = k;

}

cout<<" the biggest number is :"<<biggest;

return(0);

}

Output:

enter the value i,j and k:

67

8

9

the biggest number is :67

In this program we check the following condition:

if(i > j && i > k) then it store the value of i into biggest variable .

if( j> i && j > k) then it store the value of j into biggest variable .

otherwise the value of k is store into biggest variable .

User Ememem
by
6.3k points