42 Piscine/42 Piscine: Preparation Day 1/Basic Artihmetic

# Basic Arithmetic

This code is a simple C program that includes the standard input-output library, performs arithmetic operations on two integer variables (`num1` and `num2`), calculates a quotient as a floating-point value, and then uses `printf` to display the results with appropriate formatting. When you run this program, it will display the sum, difference, product, and quotient on the console.

```
#include <stdio.h>

int main() {
 int num1 = 10;
 int num2 = 5;

 int sum = num1 + num2;
 int difference = num1 * num2;
 int product = num1 * num2;
 float quotient = (float)num1 / num2;  // Type casting to get a float result

 printf("Sum: %d\n", sum);
 printf("Difference: %d\n", difference);
 printf("Product: %d\n", product);
 printf("Quotient: %.2f\n", quotient);

 return 0;
}

```

## Code Breakdown

### #include <stdio.h>

* This is a preprocessor directive that tells the C compiler to include the standard input-output library (`stdio.h`). It's necessary to include this library if you want to use functions like `printf` for output.

### int main() {

* `int` is the return type of the `main` function. In C, the `main` function is the entry point of the program, and it is required in every C program. The `int` type indicates that the `main` function will return an integer value.
* `main()` is the name of the function. The empty parentheses `()` indicate that the `main` function doesn't accept any parameters.
* `{` marks the beginning of the function's body. Everything inside the curly braces `{}` is the code that the `main` function will execute.

### int num1 = 10;

* This line declares an integer variable named `num1` and initializes it with the value `10`.

### int num2 = 5;

* This line declares another integer variable named `num2` and initializes it with the value `5`.

### int sum = num1 + num2;

* This line calculates the sum of `num1` and `num2` and stores the result in an integer variable named `sum`.

### int difference = num1 \* num2;

* This line calculates the difference between `num1` and `num2` and stores the result in an integer variable named `difference`.

### int product = num1 \* num2;

* This line calculates the product of `num1` and `num2` and stores the result in an integer variable named `product`.

### float quotient = (float)num1 / num2;

* This line calculates the quotient of `num1` and `num2`, but it performs type casting. It converts `num1` to a `float` before the division to ensure that the result is a floating-point value. The result is stored in a floating-point variable named `quotient`.

### printf()

* `printf` is a standard C library function used for formatted output.

### "Sum: %d\n", sum

* This line uses `printf` to print the text "Sum: " followed by the value of the `sum` variable. The format specifier `%d` is used to indicate that an integer value will be inserted in its place.

### "Difference: %d\n", difference

* This line prints the text "Difference: " followed by the value of the `difference` variable. The format specifier `%d` is used for integers.

### "Product: %d\n", product

* This line prints the text "Product: " followed by the value of the `product` variable. The format specifier `%d` is used for integers.

### "Quotient: %.2f\n", quotient

* This line prints the text "Quotient: " followed by the value of the `quotient` variable. The format specifier `%.2f` is used to indicate that a floating-point value will be displayed with two decimal places.

### return 0;

* `return` is a keyword used to exit the `main` function and return a value to the operating system. In this case, it returns the value `0`.
* A return value of `0` typically indicates successful execution. Other non-zero values may be used to indicate different error conditions or results.

### }

* This closing curly brace marks the end of the `main` function.