42 Piscine/42 Piscine: Preparation Day 2/Number Classification

# Number Classification

This C program prompts the user to enter an integer, which it stores in the variable 'number.' It then checks the value of 'number' and prints out one of three messages: "The number is positive" if 'number' is greater than 0, "The number is negative" if it's less than 0, or "The number is zero" if 'number' is exactly 0. Finally, the program returns 0 to signify successful execution. This program essentially takes a user-entered number, checks if it's positive, negative, or zero, and then displays the corresponding message.

```
#include <stdio.h>

int main() {
 int number;

 printf("Enter a number: ");
 scanf("%d", &number);

 if (number > 0) {
  printf("The number is positive.\n");
 } else if (number < 0) {
  printf("The number is negative.\n");
 } else {
  printf("The number is zero.\n");
 }

 return 0;
}

```

## Code Breakdown

### #include <stdio.h>

* This line includes the standard input-output library (`stdio.h`), which provides functions for reading input and displaying output. This is necessary to use functions like `printf` and `scanf`.

### int main() {

* This line is the beginning of the `main` function, which is the entry point of a C program. It returns an integer (`int`) and takes no arguments in this case.

### int number;

* Here, we declare an integer variable named `number`. This variable will be used to store the user's input.

### printf("Enter a number: ");

* This line uses the `printf` function to display the message "Enter a number: " to the user.

### scanf("%d", &number);

* The `scanf` function is used to read input from the user. In this case, `%d` is a format specifier for an integer. It expects the user to enter an integer, and the value entered will be stored in the `number` variable. The `&` operator is used to provide the memory address of the `number` variable so that `scanf` can store the value there.

### if (number > 0) {

* This line starts an `if` statement. It checks whether the value stored in the `number` variable is greater than 0.

### printf("The number is positive.\n");

* If the condition in the `if` statement is true (i.e., `number` is greater than 0), this line uses the `printf` function to display "The number is positive." to the console.

### } else if (number < 0) {

* If the condition in the `if` statement is false, this `else if` statement is checked. It checks whether the `number` is less than 0.

### printf("The number is negative.\n");

* If the condition in the `else if` statement is true (i.e., `number` is less than 0), this line uses `printf` to display "The number is negative."

### } else {

* If neither the `if` nor the `else if` conditions are met, the `else` statement is executed. This means that the `number` is neither greater than nor less than 0, which implies it must be equal to 0.

### printf("The number is zero.\n");

* In this case, the `printf` function displays "The number is zero" because the `number` is not greater or less than 0.

### return 0;

* The `return` statement is used to indicate that the `main` function is finished executing. It also returns an exit status of 0, which generally indicates that the program terminated successfully.