Conversions    
 
  Constantes 
 
  Kepler's laws  
 
  Unités  
 
  ask us  
 


Coding &
programming


Installing CodeBlocs compiler

C language


C++ language




© The scientific sentence. 1998-2016 
 

Programming with C Language






Using printf and scanf


In the following program, we can enter an integer, display it,
add 7 to it, and display it again:

#include <stdio.h>
int main ()
{
int value1, value2;
printf ("Enter an integer ");
scanf ("%d", &value1);
printf ("You entered value1 = %d \n", value1);
value2 = value1 +7;
printf ( "The new value is value2 = % d \n", value2);
return 0;
}


The output is:

Enter an integer 12
You entered value1 = 12
The new value is value2 = 19

Explanations :

1. Comments delimited by / * and * /
2. # include <stdio.h>
stdio.h stands for standard input / output header. This file header manages inputs and outputs standard such as scanf, printf, ...
This file includes also predefined functions that are established and provided with the compiler.
3. A block of statements is delimited between {and}
4. A statement ends with the semicolon ";"
5. We declared two integers variables value1 and value2 of type integer (int)
6. The only fuction we have is the main function "main". Instead of "void", use "int" as its type and end it with return 0;
7. printf stands for display with the suffix "f" that corresponds
to "format". %d is the code to display an integer. \n corresponds to a "new line".
8. The symbol "=" is the assignment operator
9. The scanf syntax is: scanf();
scanf("code of format", addresses of variables) ;
"scanf", that is scan with f, means "read" values with a format and deposit them at the addresses of the corresponding variables. The address operator is "&".








  

Google
  Web ScientificSentence
 


chimie labs
|
scientific sentence
|
java
|
php
|
green cat
|
contact
|


© Scientificsentence 2009. All rights reserved.