Test Forbrukslån | Paras Läppäri | Beste Kredittkort | Billigst Strøm | Billig Hyttealarm | Beste Forsikringsselskap 2017 | Billig Mobilabonnement | Billig Internett
Blog

Programming (Data type, input, output) tutorial

In this chapter we will write some small programs. Of course, all computer programs will continue and will try to compile and run a little change.

The first two numbers in the program to program. As of now, the numbers will keep the memory of the computer, how do the complex work? Not to worry! There is a thing called the Programming Language variables which are used to store a particular 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. Come on, the program is run down, and can be explained.

 #include <stdio.h>  
 int main()  
 {  
     int a;  
     int b;  
     int sum;  
     a = 50;  
     b = 60;  
     sum = a + b;  
     printf("Sum is %d", sum);  
     return 0;  
 }  
Program: 2.1
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. First, we have to say that a, b, sum of the three variables. And these will be what kind of data should be considered as well. int a; Kampailarake say we have a program in which a variable is an integer (integer) - will be used to store the value. This variable declaration to action. And the int data type, see 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 can not write separate line could write together with commas, for example: int a, b, sum ;. Notice that the variable declaration to use a semicolon at the end.
Then I wrote two statements:
a = 50;
b = 60;
The value of a- and b- values of 50 to 60 I (assign him), until we’re changing it, the compiler a- value of the standard 50 to 60 of the by- catch.
The following statement: sum = a + b ;. This means, sum-‘s value is equal to a + b-, b- a and the sum of the sum of the number of variables that we have left (or assign him).
Then the sum of the monitor to show, so we’ll use the printf function.
printf(“Sum is %d”, sum);
Printf function on the part of the two. The first part of the “Sum is% d” is meant to be printed on the screen and then Sum is an integer variable, the value of% dsum-% dsum wrote that must be straightened. Such use% d for integers, I will write something else for other types of variables, which we learn to use. It was very good that I had to write a chart of what data type C, with what they need to do in order to write and print, 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.
Thus if the above program we could write:
 #include <stdio.h>  
 int main()  
 {  
     int a, b, sum;  
     a = 50;  
     b = 60;  
     sum = a + b;  
     printf("Sum is %d", sum);  
     return 0;  
 }  
Program: 2.2
At the same time can be assigned to the variables:
 #include <stdio.h>  
 int main()  
 {  
     int a = 50, b = 60, sum;  
     sum = a + b;  
     printf("Sum is %d", sum);  
     return 0;  
 }  
Program: 2.3
Now a question for you. What will be the output of this program?
 #include <stdio.h>  
 int main()   
 {  
     int x, y;  
     x = 1;  
     y = x;  
     x = 2;  
     printf("%d", y);  
     return 0;  
 }  
Program: 2.4  
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 x- has been assigned the value 2. But it will not be any change in the quality of y-. Programming y = x; In fact, it is always an equation that can not be true. ‘=’ Symbol is placed on the value of a particular variable.
Then on the following program:
 #include <stdio.h>  
 int main()  
 {  
     int a = 50, b = 60, sum;  
     sum = a + b;  
     printf("%d + %d = %d", a, b, sum);  
     return 0;  
 }  
Program: 2.5 

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 and understand.

In order to think about the question of education, which seek to answer in the book, ask the teacher, or look on the Internet to figure out the answer to that argument. It is unfortunate that the majority of children do not finish the job, because it takes a little time to think about myself and the work, 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.

Whatever happens, when you think of the programming will be no question, together with a program that will write. What is on your compiler. For example, if we add the number of decimal type int variable (real number or a real number) used, what could have happened?

 #include <stdio.h>  
 int main()  
 {  
     int a = 50.45, b = 60, sum;  
     sum = a + b;  
     printf("%d + %d = %d", a, b, sum);  
     return 0;  
 }  
Program: 2.6
A- The use of the standard was 50.45. Now for the program, the key is on. 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; The key is to continue on the program.

Output: 50 + 60 = 110.

A- 50 has a value of C compiler, although we have 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. Int- double the number available in the Type Cast, it is automatic. Kampailarake again that can be: int a = (int) 50.45.

int a = 50.99; The value of a- 50. int a = -50.9; A- if the value is -50. Type in the words int- to double the maximum to the next part of the cast will be dropped.

To another. Casting the variable type, but does not change its value. The value can be a variable of type casting. The program, run it, the computer can understand.
 #include <stdio.h>  
 int main()  
 {  
     int n;  
     double x;  
     x = 10.5;  
     n = (int)x;  
     printf("Value of n is %d\n", n);  
     printf("Value of x is %lf\n", x);  
     return 0;  
 }  
Program: 2.7
On the output of the program. but did not change the value of x-. You can imagine that the real number to the C double type variables that are used to print% lf (l The English lowercase L) is used.

int data type can only be integer. But the key to any integer? Write a program for the answer:
 #include <stdio.h>  
 int main()  
 {  
     int a;  
     a = 1000;  
     printf("Value of a is %d", a);  
     a = -21000;  
     printf("Value of a is %d", a);  
     a = 10000000;  
     printf("Value of a is %d", a);  
     a = -10000000;  
     printf("Value of a is %d", a);  
     a = 100020004000503;  
     printf("Value of a is %d", a);  
     a = -4325987632;  
     printf("Value of a is %d", a);  
     return 0;  
 }  
Program: 2.8  
We have assigned a different number on the a-. What is the quality of being just? 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, I will say that it is. The program, run it, you will understand.

All the values ​​of a-, but could not see properly, the value of -2147483648 2147483647 to print only what will malfunction, because the number of type int variables can not be outside this range. It limits the number of type int. C type int four bytes of memory for the data (byte) is used in. This is the thirty-four-bit bytes (1 byte = 8 bit). Two things to keep every bit, 0 and 1. Keep the beats of four numbers (00, 01, 10, 11). If you can hold 32 bits: 2 ^ 32 is the number of digits 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 you understand just that.

Now we will write a program to add to the number of all real (real number) can add. 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. (on the number line, but the number of real numbers).

 #include <stdio.h>  
 int main()  
 {  
     double a, b, sum;  
     a = 9.5;  
     b = 8.743;  
     sum = a + b;  
     printf("Sum is: %lf\n", sum);  
     printf("Sum is: %0.2lf\n", sum);  
     return 0;  
 }  
Program: 2.9 
Compile the program and run it. Will output the following two lines:
Sum is: 18.243000
Sum is: 18.24
% Of the first in line to use the maximum of six houses have been printed. There are two rooms on the second line after the columns have been printed, the% 0.2lf written (if you want to print up to three houses% 0.3lf writing, if you do not want to print part of the decimal% 0.0lf). 64-bit double data type is used for and 1.7E-308 (1.7 x 10-308) to 1.7E + 308 (1.7 x 10308) until the data can be kept. Some of the food here is more scientific calculation needs to understand the details of the computer, so I’m not going to turn now.
Now we want to make it in our program, so there is no need to add the two numbers in it, we do not write the code, 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 (C has more functions for this purpose). So do not delay the program wrote:
 #include <stdio.h>  
 int main()  
 {  
     int a, b, sum;  
     scanf("%d", &a);  
     scanf("%d", &b);  
     sum = a + b;  
     printf("Sum is: %d\n", sum);  
     return 0;  
 }  
Program: 2.10 
When you run the program you see the 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 function scanf. scanf (“% d”, & a); The double quotation is called scanf- with the% d or int is an integer value that will be read (the user to input from the keyboard). And on the emaparasenda a- (&) symbol is used, na has meant that the number will be assigned to the input will be given the a variable. You will learn the C bit, then you will understand the true meaning of a-, we are going to pay attention. b- values ​​of a and could be a function of the scanf: scanf (“% d% d”, & a, & b) ;. What is the problem if I do not sign before the variable & c? Try to run the program, to be able to make an error. Erarata not explain this right now, because the explanation is a little complicated to explain, and now you may understand what went wrong, and then I will be cursed.
 #include <stdio.h>  
 int main()  
 {  
     int a, b, sum;  
     scanf("%d", &a);  
     scanf("%d", b);  
     sum = a + b;  
     printf("Sum is: %d\n", sum);  
     return 0;  
 }  
Program: 2.11

Now, if we double the input of the integer data type to do what you would have wanted? scanf- were simply use the% d-% lf instead. Write to run the program and on what you do well. 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 difficult as it may seem, it will compile and run down the computer. If this does not work, can not move forwards. Remember, there is no alternative to driving, such as driving lessons, swimming, learning to swim as there is no alternative, as there is no alternative to programming for learning programming, the programmer can not be just a book.

Then we will see another type of data, it is char (character) type. So this type of character, the 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 letters of the English alphabet, the letter will be the character of another language can not be a variable of type char. The program also runs in the bottom of the computer by typing:

 #include <stdio.h>  
 int main()  
 {  
     char ch;  
     printf("Enter the first letter of your name: ");  
     scanf("%c", &ch);  
     printf("The first letter of your name is: %c\n", ch);  
     return 0;  
 }  
Program: 2.12
Code look-know, char type in the printf and scanf function is to use% c. There is another function getchar, it can also be read char data type. On the following program:
 #include <stdio.h>  
 int main()  
 {  
     char ch;  
     printf("Enter the first letter of your name: ");  
     ch = getchar();  
     printf("The first letter of your name is: %c\n", ch);  
     return 0;  
 }  
Program: 2.13
It also runs. The program will work the same as before. ch is a character variable in the function to get char was assigned. 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';
Now on the following program:
 #include <stdio.h>  
 int main()  
 {  
     int num1, num2;  
     printf("Please enter a number: ");  
     scanf("%d", &num1);  
     printf("Please enter another number: ");  
     scanf("%d", &num2);  
     printf("%d + %d = %d\n", num1, num2, num1+num2);  
     printf("%d - %d = %d\n", num1, num2, num1-num2);  
     printf("%d * %d = %d\n", num1, num2, num1*num2);  
     printf("%d / %d = %d\n", num1, num2, num1/num2);  
     return 0;  
 }  
Program: 2.14
It also compiles and runs. It certainly understand subtraction, multiplication and division are working to learn how. Then the four of you are working. One, num1 and between num2- addition, subtraction, multiplication, division work before the printf function and value of a variable in left. Write a program for. The second work program is being used as a variable of type double. The third act, num 2-on with a value of 0 is the key. The fourth task is the printf function inside the double quotation of the +, -, *, / symbols which are not used directly in a variable of type char is used then. After four work properly on the following program:
 #include <stdio.h>  
 int main()  
 {  
     int num1, num2, value;  
     char sign;  
     printf("Please enter a number: ");  
     scanf("%d", &num1);  
     printf("Please enter another number: ");  
     scanf("%d", &num2);  
     value = num1 + num2;  
     sign = '+';  
     printf("%d %c %d = %d\n", num1, sign, num2, value);  
     value = num1 - num2;  
     sign = '-';  
     printf("%d %c %d = %d\n", num1, sign, num2, value);  
     value = num1 * num2;  
     sign = '*';  
     printf("%d %c %d = %d\n", num1, sign, num2, value);  
     value = num1 / num2;  
     sign = '/';  
     printf("%d %c %d = %d\n", num1, sign, num2, value);  
     return 0;  
 }  
Program: 2.15
The program will be able to see what works. But it just will not see any difference however. Compile and execute code.

C also has some data type. There are also various methods of input and output, which you will learn slowly (in the book may not be able to read other books C). Now what you have learned through many programs you will be able to write.

Now would be a fun and useful things. You can use your own language code in the program. This is called comment (comment) is. The program is part of the compiler will not kamentaguloke. // Mark the one-line comments can start with a comment. If more than one line in the / * and * the start / end with. But in order to compile and run the program.
 #include <stdio.h>  
 int main()  
 {  
     // test program - comment 1  
     printf("Hello ");  
     /* We have printed Hello,  
     now we shall print World.  
     Note that this is a multi-line comment */  
     printf("World"); // printed world  
     return 0;  
 }  
Program: 2.16
Then a question, (which would be the beginning of the C text book chapter), the naming of variables, what rules? Variable name can be one or more characters, the characters may be from a zA Z0 9 and _ (underscore or andarabara). However, the first letter address 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, if the sum of the sum to the variable name, like the name, but the program moves y. To understand the meaningful name, bheriyebalata key has been used for the purpose.

Comments

comments

About the author

Toriqul Islam Tusher

বলার মত কিছু নাই!

Leave a Comment