Saturday, June 20, 2015
[Programming book Chapter Two] data type, input and output.
In this chapter we will write some small programs. Of course, the computer will continue all the programs and will try to compile and run a little change.
Our first two numbers to program to program. Now, the numbers will keep the memory of the computer, how do the complex work? Not to worry! There is a thing of the Programming Language Variables that are used to contain a specific value. Is a variable name, then write down the value of the variable in any of the variables = goes into it. But it has nothing to do with the mathematical equations.
The program also runs, you will see on the screen: Sum is 110.
Here a, b, sum of three variables (variable) that contain different numbers. Will be the first to tell us that a, b, sum of the three variables. And these will also have to tell what kind of data. int a; Kampailarake say we have a program in which a variable is an integer (integer) - will be used to store the value. This action tells the variable declaration. And the data type int, which saw the C compiler know that it will be the integer data type. There are several data types, which we will look quietly. We want to declare the variables of the same type together in a separate line without the comma could write, for example: int a, b, sum ;. Notice that the variable declaration to use the semicolon at the end.
Then I wrote two statements:
a = 50;
b = 60;
Here the value of a- and b- values of 50 to 60 I (assign I), until we're changing it, the compiler of the value of a- and b- values of 50 to 60 will.
The next statement is: sum = a + b ;. This means, sum-'s value is equal to a + b-, b- and a sum of the sum of the number of variables that we stuck with it (or assign I).
Now the sum of the monitors will show, so we'll use the printf function.
printf ("Sum is% d", sum);
Here on the part of the printf function. The first part of the "Sum is% d" is meant to be printed on the screen and then Sum is an integer variable, which will replace the% d-. Then write-downs, we have explained that the sum of the value of the print sum-% d- on. For example, use% d for integers, I will write something else for other types of variables, which we can learn to use. Would be very good if I had written a chart of what type of data are coded in C, with what they need to do the writing and printing, and you have to memorize the chart. But there is just no need to memorize, memorize and reduce the tendency to think of the ability to think is very important for programmers.
What do you think? Output 1 or 2? The output will be 1, because the compiler will, x- value of 1 has been assigned to (x = 1;). The value of the x- and y- has been assigned to the (y = x;). Now y- value of 1. Then again, the value of x- 2 has been assigned to. But it will not be any change in the quality of y-. Programming y = x; In fact, it is an equation that can not be always true. '=' Symbol is placed on the value of a particular variable.
The program monitors the print key? Continue on. printf ("% d +% d =% d", a, b, sum); Writing printf ("% d +% d =% d", b, a, sum); For entering the program. Now think about things that do not understand.
While studying many of us think about the question, the answer is that we look for in the book, ask the teacher, or look for the thought that the reasoning set out to answer. It is unfortunate that most of our children do not finish the job, because it takes a little time to myself to think and work, and the time and effort they want to do. And our parents, teachers, and education does not need to worry about any reward, but the reward to memorize.
However, whenever any question of programming will, together with a program to be written. What is on your compiler. Suppose, if we add the number of decimal int type variable (real number or a real number) used, what would have happened then?
Here I used a- value of 50.45. Now for the program, see what happens. Once again the question that comes to mind, main function at the finish line return 0; What happens if you do? If you return 0; What is on the program to continue.
Output will be: 50 + 60 = 110.
A- C compiler has a value of 50, even though we've assigned to 50.45. This is the type of matter casts (type cast). The real number to double by the name of the C language has a data type. Double the number and type casts are available at int-, it is automatic. Kampailarake again that can be: int a = (int) 50.45.
int a = 50.99; Here the value of a- 50. int a = -50.9; A- if the value of -50. Type in the words of one int- to double the maximum to the next part of the cast will be dropped.
Another thing. Casting the variable type, but does not change its value. A variable can hold a value of type casting. The program, run it, the computer can understand.
On the output of the program. but did not change the value of x-. And you-know-that the real number to double that on C-type variables are used, it's time to print% lf (l here English lowercase L) is used.
int data type can hold only whole numbers. But the key to any integer?
Here we have assigned a different number on a-. Well what is the value? Did. Why did it take a while before the show. Surely you see the computer screens of many consecutive printf- feel a little uncomfortable. Thus, if you write the printf: printf ("Value of a is% d \ n", a) ;. Now, printf function "of" in the \ n if you do not know what I should say that it is. The program, run it, you will understand.
All the values of a-, but could not see properly, the value -2147483648 2147483647 far from where they will print well, because outside of this range can not be a variable of type int. It limits the number of type int. Int data type in C for four bytes of memory (byte) space is used. This is the thirty-four-bit bytes (1 byte = 8 bit). Two things have kept every bit, 0 and 1. Available in two beats four numbers (00, 01, 10, 11). If you can hold 32 bits: 2 ^ 32 is the number of hours the number 4294967296. Now if you put half positive and half negative, then -2147483648 2147483647 0 from -1 to the total number 2147483648 2147483648 total numbers, the total number 4294967296. I hope, understand rise.
Now we are going to write the program to add all the real numbers (real number) can be added. Let remind you, is an integer, ... -3, -2, -1, 0, 1, 2, 3 ... etc. The real number is 5, 3, -2.43, 0, 0.49, 2.92, etc. (about the number, but the number of real numbers).
Compile and execute the program. It will output the following two lines:
Sum is: 18.243000
Sum is: 18.24
As a first line after the decimal% lf six houses have been printed so far. There are two rooms on the second line after the columns have been printed, because% 0.2lf written (if you want to print up to three houses% 0.3lf writing, if you do not want to print the decimal part% 0.0lf). 64-bit double data type is used for the 1.7E-308 (1.7 x 10-308) to 1.7E + 308 (1.7 x 10308) of the data can be kept. In order to understand the details of the computer scientific calculation needs more food here, so I'm not going to turn now.
Now the system we want to keep our program, so there is no need to add the two numbers that we do not write the code in, in the form of input from the user will see. The user (meaning that the program is using) from the input to the function that we'll use scanf (Sea has further functions for this purpose).
When you run the program you will see a blank screen (blank screen) comes. When you write a number, then the space (space) or ENTER (enter) the write another number. Then press Enter again to see the sum.
Surely you have learned to use the scanf function. scanf ("% d", & a); Here is the% d in double quotation scanf- Who is to say that the value of an integer or a variable of type int read (the user input from the keyboard). Earlier on the a- emaparasenda (&) symbol is used, & a has meant that the number of input will be assigned to a variable between. C. When you learn a little more closely, you will understand the true meaning of the & a-, we are going to pay attention to. b- values of a and thus could take a scanf function: scanf ("% d% d", & a, & b) ;. What is the problem if I do not sign before the variable &? Try to run the program, some will be an error. Erarata're not explain this right now, because you can not understand the implications may mean a little more complicated, and now and then I will be cursed.
Now, if we wanted to take as input integer data type, if you do not have a double? scanf- were simply using the% d-% lf instead. Fellow entering the program and what is on the run malfunction. Then read the rest of the start.
In fact, it will not run properly, because of the need to change the data type. Int does not have to write down the double. Restart the program.
Whenever I would write a book, any program simple or as difficult as it may seem, it will compile and run down the computer. If this does not work, you can not move forwards. Remember, there is no alternative to driving, such as driving lessons, swimming lessons and swimming, as there is no alternative, as there is no alternative to programming for learning programming, the programmer can not be just a book.
Now we look at another type of data, it is char (character) type. This is the type of character to character is the only one for each byte of memory space is required. Usually this type of data for any of the characters or symbols are used. However, the letter of the English alphabet letters will be, other language characters can not be a variable of type char.
The program will work the same as before. getchar function is a letter that was assigned in the variable ch. And if you want to direct some of the char type variable, the two sides will sign the letter or the single quotation marks. For example: char c = 'A';
It also compiles and runs. It surely understand subtraction, multiplication and division are working to learn how. Now your job is four. One, num1 and between num2- addition, subtraction, multiplication, division work before the printf function and value of a variable in left. Fellow entering a program for. The second work program is being used as a variable of type double. The third act, num2- on the key's value is 0. The fourth task is the printf function inside the double quotation of the +, -, *, / symbols which are not used directly with a char type variable is used then.
In this chapter we will write some small programs. Of course, the computer will continue all the programs and will try to compile and run a little change.
Our first two numbers to program to program. Now, the numbers will keep the memory of the computer, how do the complex work? Not to worry! There is a thing of the Programming Language Variables that are used to contain a specific value. Is a variable name, then write down the value of the variable in any of the variables = goes into it. But it has nothing to do with the mathematical equations.
The program also runs, you will see on the screen: Sum is 110.
Here a, b, sum of three variables (variable) that contain different numbers. Will be the first to tell us that a, b, sum of the three variables. And these will also have to tell what kind of data. int a; Kampailarake say we have a program in which a variable is an integer (integer) - will be used to store the value. This action tells the variable declaration. And the data type int, which saw the C compiler know that it will be the integer data type. There are several data types, which we will look quietly. We want to declare the variables of the same type together in a separate line without the comma could write, for example: int a, b, sum;. Notice that the variable declaration to use the semicolon at the end.
Then I wrote two statements:
a = 50;
b = 60;
Here the value of a- and b- values of 50 to 60 I (assign I), until we're changing it, the compiler of the value of a- and b- values of 50 to 60 will.
The next statement is: sum = a + b;. This means, sum-'s value is equal to a + b-, b- and a sum of the sum of the number of variables that we stuck with it (or assign I).
Now the sum of the monitors will show, so we'll use the printf function.
printf ("Sum is% d", sum);
Here on the part of the printf function. The first part of the "Sum is% d" is meant to be printed on the screen and then Sum is an integer variable, which will replace the% d-. Then write-downs, we have explained that the sum of the value of the print sum-% d- on. For example, use% d for integers, I will write something else for other types of variables, which we can learn to use. Would be very good if I had written a chart of what type of data are coded in C, with what they need to do the writing and printing, and you have to memorize the chart. But there is just no need to memorize, memorize and reduce the tendency to think of the ability to think is very important for programmers.
What do you think? Output 1 or 2? The output will be 1, because the compiler will, x- value of 1 has been assigned to (x = 1;). The value of the x- and y- has been assigned to the (y = x;). Now y- value of 1. Then again, the value of x- 2 has been assigned to. But it will not be any change in the quality of y-. Programming y = x; In fact, it is an equation that can not be always true. '=' Symbol is placed on the value of a particular variable.
The program monitors the print key? Continue on. printf ("% d +% d =% d", a, b, sum); Writing printf ("% d +% d =% d", b, a, sum); For entering the program. Now think about things that do not understand.
While studying many of us think about the question, the answer is that we look for in the book, ask the teacher, or look for the thought that the reasoning set out to answer. It is unfortunate that most of our children do not finish the job, because it takes a little time to myself to think and work, and the time and effort they want to do. And our parents, teachers, and education does not need to worry about any reward, but the reward to memorize.
However, whenever any question of programming will, together with a program to be written. What is on your compiler. Suppose, if we add the number of decimal int type variable (real number or a real number) used, what would have happened then?
Here I used a- value of 50.45. Now for the program, see what happens. Once again the question that comes to mind, main function at the finish line return 0; What happens if you do? If you return 0; What is on the program to continue.
Output will be: 50 + 60 = 110.
A- C compiler has a value of 50, even though we've assigned to 50.45. This is the type of matter casts (type cast). The real number to double by the name of the C language has a data type. Double the number and type casts are available at int-, it is automatic. Kampailarake again that can be: int a = (int) 50.45.
int a = 50.99; Here the value of a- 50. int a = -50.9; A- if the value of -50. Type in the words of one int- to double the maximum to the next part of the cast will be dropped.
Another thing. Casting the variable type, but does not change its value. A variable can hold a value of type casting. The program, run it, the computer can understand.
On the output of the program. but did not change the value of x-. And you-know-that the real number to double that on C-type variables are used, it's time to print% lf (l here English lowercase L) is used.
int data type can hold only whole numbers. But the key to any integer?
Here we have assigned a different number on a-. Well what is the value? Did. Why did it take a while before the show. Surely you see the computer screens of many consecutive printf- feel a little uncomfortable. Thus, if you write the printf: printf ("Value of a is% d \ n", a);. Now, printf function "of" in the \ n if you do not know what I should say that it is. The program, run it, you will understand.
All the values of a-, but could not see properly, the value -2147483648 2147483647 far from where they will print well, because outside of this range can not be a variable of type int. It limits the number of type int. Int data type in C for four bytes of memory (byte) space is used. This is the thirty-four-bit bytes (1 byte = 8 bit). Two things have kept every bit, 0 and 1. Available in two beats four numbers (00, 01, 10, 11). If you can hold 32 bits: 2 ^ 32 is the number of hours the number 4294967296. Now if you put half positive and half negative, then -2147483648 2147483647 0 from -1 to the total number 2147483648 2147483648 total numbers, the total number 4294967296 . I hope, understand rise.
Now we are going to write the program to add all the real numbers (real number) can be added. Let remind you, is an integer, ... -3, -2, -1, 0, 1, 2, 3 ... etc. The real number is 5, 3, -2.43, 0, 0.49, 2.92, etc. (About the number, but the number of real numbers).
Compile and execute the program. It will output the following two lines:
Sum is: 18.243000
Sum is: 18.24
As a first line after the decimal% lf six houses have been printed so far. There are two rooms on the second line after the columns have been printed, because% 0.2lf written (if you want to print up to three houses% 0.3lf writing, if you do not want to print the decimal part% 0.0lf). 64-bit double data type is used for the 1.7E-308 (1.7 x 10-308) to 1.7E + 308 (1.7 x 10308) of the data can be kept. In order to understand the details of the computer scientific calculation needs more food here, so I'm not going to turn now.
Now the system we want to keep our program, so there is no need to add the two numbers that we do not write the code in, in the form of input from the user will see. The user (meaning that the program is using) from the input to the function that we'll use scanf (Sea has further functions for this purpose).
When you run the program you will see a blank screen (blank screen) comes. When you write a number, then the space (space) or ENTER (enter) the write another number. Then press Enter again to see the sum.
Surely you have learned to use the scanf function. scanf ("% d", & a); Here is the% d in double quotation scanf- Who is to say that the value of an integer or a variable of type int read (the user input from the keyboard). Earlier on the a- emaparasenda (&) symbol is used, & a has meant that the number of input will be assigned to a variable between. C. When you learn a little more closely, you will understand the true meaning of the & a-, we are going to pay attention to. b- values of a and thus could take a scanf function: scanf ("% d% d", & a, & b);. What is the problem if I do not sign before the variable &? Try to run the program, some will be an error. Erarata're not explain this right now, because you can not understand the implications may mean a little more complicated, and now and then I will be cursed.
Now, if we wanted to take as input integer data type, if you do not have a double? scanf- were simply using the% d-% lf instead. Fellow entering the program and what is on the run malfunction. Then read the rest of the start.
In fact, it will not run properly, because of the need to change the data type. Int does not have to write down the double. Restart the program.
Whenever I would write a book, any program simple or as difficult as it may seem, it will compile and run down the computer. If this does not work, you can not move forwards. Remember, there is no alternative to driving, such as driving lessons, swimming lessons and swimming, as there is no alternative, as there is no alternative to programming for learning programming, the programmer can not be just a book.
Now we look at another type of data, it is char (character) type. This is the type of character to character is the only one for each byte of memory space is required. Usually this type of data for any of the characters or symbols are used. However, the letter of the English alphabet letters will be, other language characters can not be a variable of type char.
The program will work the same as before. getchar function is a letter that was assigned in the variable ch. And if you want to direct some of the char type variable, the two sides will sign the letter or the single quotation marks. For example: char c = 'A';
It also compiles and runs. It surely understand subtraction, multiplication and division are working to learn how. Now your job is four. One, num1 and between num2- addition, subtraction, multiplication, division work before the printf function and value of a variable in left. Fellow entering a program for. The second work program is being used as a variable of type double. The third act, num2- on the key's value is 0. The fourth task is the printf function inside the double quotation of the +, -, *, / symbols which are not used directly with a char type variable is used then.
Now a question, (which is to say at the beginning of the C text book used in this chapter), the naming of variables, what rules? Variable name can be one or more characters, the characters may be from a z, A to Z, 0 to 9, and _ (underscore or andarabara). However, the first letter in the address of multiple characters (digits) can not be. You have a program int 7d; What is written on the compiler. If the variable names are meaningful. For example, for obtaining the sum of the sum of the variable name only better, even though the name of the program to y. To understand the meaningful name, bheriyebalata key has been used for the purpose.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment