This month put an old article as I have a friend asked me ... is beginning in C ++...
I'll write in program source (where you enter) and explain the syntax (as it should be written) the same: # include
# include
void main ()
{
clrscr ();
int a, b, c, sum;
printf ("Enter first number:");
scanf ("% d", & a);
printf ("Enter the second nĂșemro:");
scanf ("% d", & b);
printf ("Enter the third numeri:");
scanf ("% d", & c);
sum = (a + b + c);
printf ("\\ n The sum of the numbers is:% d", sum);}
This is a simple program that performs the sum of three integers, I now proceed to explain the syntax of it (what most important):
1. You place the "Policies" are those that define the program figuratively. Are directives that indicate the kinds of input and output devices and their configuration. So I put # include # include
2. After that you put void main (). "Void" tells us that does not return or return information. "Main ()" is an input method that tells the program running.
3. You should put a parenthesis indicates that the same body of the program, which begins and where it ends. First is "{" then "}". That last parenthesis should go to the end of the whole body of the program.
4. clrscr () india wiping everything on screen is not removed, but whitening.
5. After this, you must declare the variables (to change, you change the value several times) and constant (no change, just the statements, the program is not allowed to change this value), how?, If you put the word variable reserved "int" integer, which tells us that is whole and only accept integer values. If eg enter 2, she grabs the 2, if you enter 2596, it only holds the number 2, you indicated that it was over, the variable is going to take that value. If you want grip and decimals, then back to be "int", you must put "float" for floating, that tells us that grabs whole with or without decimals. When you declare a constant you do with the word "const", you give a space, followed by the name of the constant, with value. So: const pi = 3.1415927.
6. Next, you send a message to request the value to use, I put "Enter the first number:" you can put the one you want. When you're printing a message you place the word "printf" followed by a parenthesis, in the same place it stretchers, write the message and close quotes. What is inside quotation marks indicate that it is a constant alphanumeric (letters and numbers) in this case. It can also be numbers.
7. Then, put the keyword "scanf ("% f ",%" X "). The scanf it does is to capture the value you entered, in replying to the message that asks for the data at the time of executing the program. You add the parentheses, quotation marks in a row, "% f" (the "f" belongs to printf, so capture that value), the comma after the "&" (The "&" is part of the syntax) next to the variable that will contain the value you entered. Put "X" because it is the variable that will contain the value. It may be "a" or "salary" so to speak (I'm telling you that what you write in quotes is a constant). This should do it as often as necessary, if at least two variables declared, you must do it twice to give a value to each (twice "printf" and "scanf" ... first put "printf" and then "scanf") , This should do it depending on many variables (which you must enter a value, if constant not, that is the gave, remember what I put above!) has declared.
8. Then you must put the expression that will run the computer, look up as you write.
9. Send a message indicating what the outcome. I send to print (not print to the printer, but put it on the screen) "The sum of the numbers is:" That depends on what you do ... I explained?
10. At the end you've already written all you skip a line or space and you put the key that I've told you to put on.
is Hope you enjoyed this little article and if you have any questions, write to me mail, which I gladly will resolve the doubt ...
Until the next ... well ...
portencen others Let them know you like it to be able to expand this space ...
Goodbye and the next ... Saellvertu!!
0 comments:
Post a Comment