Practice #1
Tags: c, beginners, tutorial
Published: 2019-06-14 10:17:44

First, we should have an environment where we can write and run ours code. This type of program is called: [Integrated Development Environment (IDE)](https://en.wikipedia.org/wiki/Integrated_development_environment).

A list of Recommended IDEs:
- [Visual Studio](https://visualstudio.microsoft.com/vs/features/cplusplus/) (Microsoft)
- [Clion](https://www.jetbrains.com/clion/)  (JetBrains)
- [Eclipse](https://www.eclipse.org/downloads/packages/release/2019-03/r/eclipse-ide-cc-developers)

In this tutorial, we will use [Eclipse](https://www.eclipse.org/downloads/packages/release/2019-03/r/eclipse-ide-cc-developers). But feel free to use any other IDE that you want. It completely depends on personal preferences. I don't teach here how to download and install an IDE on purpose, because the version of the IDE and the download and install instructions may be a little different when you read this post. Just follow the instructions on the website of the IDE you chose and it will be totally fine. (If you need any help, just send me an email about that).

Ok, so let's begin.

Open the IDE and then create new __Console App__ project. After that, just make sure that the source file you are writing in has a ".c" suffix and not a ".cpp" suffix (if not, just rename the file).

Now, write your first code:
```cpp
#include <stdio.h>

int main()
{
    printf("Hello World!\n");
}
```
And run it! (Usually, you can do that by pressing F5. Again, just follow the instructions of the IDE you chose). In a console, (which will be opened), you have to see "Hello world!". If you saw that, __congratz__ - you wrote and ran your first code!

Let's write some more complicated code now:
```cpp
#include <stdio.h>

int getUserInput() {
	int input;
	// Gets input from the user
	printf("Insert a number:\n");
	scanf("%d", &input);
	return input;
}

void isDivideWithoutRemaining(int x, int y) {
    // The '%' operator performs the modulo operation
	if (x % y == 0) {
		int z = x / y;
		printf("%d number can be divided without a remainder by %d and the result is %d", x, y, z);
	} else {
		printf("%d cannot be divided without a remainder by %d", x, y);
	}
}

int main()
{
	// Gets two numbers from the user
	int x = getUserInput();
	int y = getUserInput();
	// Checks if the first number can be divided without a remainder by the second number
	isDivideWithoutRemaining(x, y);
	// Success
	return 0;
}
```
For example:
```cpp
Insert a number:
10
Insert a number:
2
10 number can be divided without a remainder by 2 and the result is 5
```

Read here about [modulo](https://en.wikipedia.org/wiki/Modulo_operation), if you needed (The '%' operator in C). 

If you are using Visual Studio, for now, just write above your code the follows:
```cpp
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
```
any time you uses ___scanf___. If you want to understand why just Google it. It's really not important. You can see another solution [here](https://stackoverflow.com/questions/16883037/remove-secure-warnings-crt-secure-no-warnings-from-projects-by-default-in-vis).

Write this code and make sure you understand what it does.

That's all for today, Have fun keep practicing some C by yourself! (There is no better way, trust me. If you need an idea, try to write a code which gets 2 numbers from the user and then prints all the mathematics operations. For example, if our variables are _x_ and _y_ it will print: _x_+_y_, _x_-_y_, _x_*_y_, _x_/_y_ with appropriate explanations and comments).

####__Always remember, it's much C-mpler than you thought!__

Regards,
Gilad