Tuesday, August 15, 2017

C programming; Lesson 7: Assignment operator



Assignment operator joins the value of the expression on the right to the value of the variable on the left side. The type of expression value should match the type of variable.
Example:
                int a = 5; (value 5 is given  to the variable a)

Monday, August 14, 2017

C programming;Lesson 6: Operators for formatting the output

Special Signs for Surveillance:
                       constance                                                   meaning 
                            \b                                               movement for one place left                                                                     \n                                                            new line                                                                                       \f                                                           new page                                                                                       \t                                                       horizontal tab                                                                                   \"                                                      quotation letter                                                                                   \\                                                    backslash character 
                            \?                                                      question mark

Example: 
              printf ("This is the first line. \n"); 
              printf ("This is the second line");
              printf ("\n \tThis is the third line and moved to the right");

Additional forms of variable formats:
The format "%2d" determines that the variable is a two-digit number.

Example: 
                 int a; 
                 scanf ("%2d", &a);
                 printf ("%d");


The format "% .2f" determines that the variable is a real number written in decimal form with two decimal places.
Example: 
                 float a;
                 scanf ("%f", &a);
                 printf ("%.2f", a);










Sunday, August 13, 2017

C programming;Lesson 5: Getting keyboard input

To load data from the keyboard, use the scanf function.
The shape of the function is:  
                                               scanf ("list_of_formats", list_of_variable_address);

The variable address can be obtained by using the operator & before the variable name, while the variable formats are the same as the case of printing data on the screen. 
An example of loading a variable from the keyboard: 
                                                                                      int a;
                                                                                      scanf ("%d", &a);

An example of loading multiple keystrokes variables: 
                                                                                     int a; 
                                                                                     float b; 
                                                                                     scanf ("%d%f", &a, &b); 
                                                                                     scanf ("%d,%f", &a, &b);

C programming; Lesson 4:Print on screen


We use the printf function to print on the screen.

If we only want to print a text message the form of the function is:

                                                                    printf ("string of characters to be printed on the screen");

If we want to print a value stored in a particular variable, the form of the function is:

                                                                                           printf ("list_format", variable_lists);

In the format list, we list the variable format we want to print. The format of the variable consists of the character% and type of format:
                                        format                                         meaning                                                                                                    %c                                      Load one character                                                                                          %d                                      Load integer                                                                                                    %f                                       Load real number                                                                                            %s                                       Load string                                                                                                      %u                                      Print decimal number unsigned


Example of printing only a value of a variable :
                                       
                                         int a = 5;
                                         printf ("%d", a);


Example of text output and variable value:

                            int nm_stud = 7;
                            float average = 4.15;
                            printf ("The number of students is%d, and their average is%f", nm_stud, average);







Saturday, August 12, 2017

C Programming; Lesson 3: Numbers and Characters

Numbers:

In the C language there are essentially two types of numbers:
                                          integers
                                          real numbers (floating-point numbers)

             type                                         bytes                    range value                                                                   char                                            1                       -128 to 127                                                                      int                                              2                     -32768 to 32767                                                            short int                                         2                     -32768 to 32757                                                             long int                                         4                  -2147483648 to 2147483647                                             float                                            4               -3.4 * 10^38 to -3.4 * 10^38 and                                                                                                                3.4 * 10^-38 to 3.4 * 10^38                                                 double                                           8              -1.7 * 10^308 to -1.7 * 10^-308 and                                                                                                          1.7 * 10^-308 to 1.7 * 10^308                                          long double                                    10              -1.1 * 10^4932 to -3.4 * 10^-4932 and                                                                                                       3.4 * 10^-4932 to 1.1 * 10^-4932
If the type of variable is defined with the additional word unsigned then the range is moved to the positive area.

Characters:

char- serves to save the ASCII values of a single character.
To save a character we use: char a = 'b';

Friday, August 11, 2017

C programming; Lesson 2: Variables

Types of data in the program:
                                constants (0, 5, 3,145)
                                variables (a, iNumber, p)

For naming (variables and functions), identifiers are used:
                                English alphabet letters (A - Z, a - z), numbers (0 - 9) and underscore ('_')
                                First sign must be a letter or underscore
                                The identifier may not be the same as one of the keywords

(Language C differs in lowercase, so that the identifiers a and A are different names). Before using any variable, it is necessary to declare it in order for the compiler to know how many memory locations to reserve for that variable. The Declaration consists of the type of variable and identifier.
for example:  int a, b, c;

No more variables with the same name can be declared in the same part of the program (in the same block). After the variable declaration, the translator will reserve a certain area in memory for that variable under that name. At that point, anything can be found in the memory at that point, so it is necessary to set its value before initial use of the variable (initialize).
for example:   int a;
                       a = 5;

or:   int a = 5;

The join operator changes the value of a variable, and the variable type remains unchanged. If the operands are to the left and right of the join operator of different types, the value is lowered to the operand type according to the defined conversion rules. On the left side of the join operator, there are only changeable objects (variables). Multiple assignment operators are allowed in the same command.




Sunday, August 6, 2017

C programming; Lesson 1: Main program and definition of variables

The simplest program in C would be:
int main () {
return 0;
}
main is the name for the main function in each C program and every program written in C must have exactly one main function. It should be noted that this is only a symbolic name that gives the compiler an idea of which part of the program to start running first.
The word int in front of the tag of the main function indicates that the main () after the completion of the commands and functions contained therein will return a whole number (integer) as a result of this execution. As the main program runs from the operating system, the result of the main program is returned to the operating system. Most often, this is a code that signals an error occurring during a program run or a notification of a successful execution.

Behind the word main follows the open-closed bracket. Within these brackets should come data descriptions that are transmitted from the operating system to main (). These data are called function arguments. In this example of the program no arguments are transmitted.

After that comes an open left brace that marks the beginning of a block in which the main function commands will be located, while a closed, right brace at the bottom line indicates the end of that block. Within the braces of the the program there is a return 0, which means that the main program returns the number 0, which is a message to the operating system that the program has been successfully completed, whatever his function was.
Sign ; after returns 0 indicates the end of the command and serves as a message to the compiler that all the following characters interpret as a new command.
Another example of the program is:

#include <stdio.h>

int main () {
printf ("These are Exercises");
return 0;
}

In this example there is a command #include <stdio.h> which requires the compiler to include the stdio.h library in our program. In this library, there is an output stream of functions that allows you to print data on the screen. It is necessary to emphasize that include is not a C command, but it is a preprocessor command. After finding it, the translator will stop the process of translating the code into the current file, jump to stdio.h, translate it, and then return to the translation in the startup file.