Skip to content

Show Biggest


Show Biggest program

Make a program that receives 3 numbers and returns the biggest one.

Execute

Clone main branch from c-cpp-projects.

Access this folder on terminal:

  cd c-cpp-projects/c_exercises/show_biggest

Run with GCC compiler

With GCC compiler installed run the following commands:

  1. Compile the cpp file:

    gcc show_biggest.cpp -o execute -lm
    
  2. Run the execute compiled file:

    ./execute
    

Run with Docker

With Docker installed run the following commands:

  1. Build the container and images:

    docker build -t gcc-docker .
    
  2. Run the container with the built image gcc-docker:latest:

    docker run -it gcc-docker:latest
    

Code

Code in C.

#include <stdio.h>

int main (void)
{
 int n1,n2,n3, biggest;

 printf("\nType the first number: \n");
 scanf(" %d", &n1);
 printf("\nType the second number: \n");
 scanf(" %d", &n2);
 printf("\nType the third number: \n");
 scanf(" %d", &n3);

 if (n1 > n2 && n1 > n3){
  biggest = n1;
 } else if ( n2 > n1 && n2 > n3){
  biggest = n2;
 } else if ( n3 > n1 && n3 > n2){
  biggest = n3;
 }

 printf("\nBiggest:\n%d\n", biggest);
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.