Standard output function scanf

(1) format specifier can specify the width of the data, but does not specify the accuracy of the data. example: 

1
2
3
float  a;
scanf (“%10f”,&a);   //正确
scanf (“%10.2f”,&a);  //错误

    

(2) Input% ld must be used when long data types, double data must be input or% lf% le. 
(3) Additional Format specifier "*" corresponding to the input data is not assigned to the corresponding variables. 
scanf () function used in the conversion specifier printf (used almost identical). The main difference is that printf () the% f,% e,% E ,% g,% G float and double types used for both types, and scanf () float type just for them, and for the double type requires use l (the letter l) modifier.

Conversion specifier  
%c Interpreted as a character input
%d Input interpreted as a signed decimal integer
%e,%f,%g,%a Input interpreted as a float (% a C99 standard is)
%E,%F,%G,%A Input interpreted as a float (% A C99 is standard)
%i Input interpreted as a signed decimal integer
%O The input interpreted as a signed octal integer
%p Input interpreted as a pointer (address)
%s Input interpreted as a string: the contents of the input to the first non-blank character as a start, and all the characters comprising blank characters until the next
in% Input interpreted as an unsigned decimal integer
%x,%X Input explained that a signed hexadecimal integer

 

* Modifier usage in scanf () are:

* Providing distinct services scanf (), when it is placed between the specifier and the letters%, it makes the function skips the corresponding input item

A free-fall prone to error computing code

. 1 #include <stdio.h>
 2  
. 3 #include <math.h>                     // later need to use the power required POW () function 
. 4  
. 5  int main () {
 . 6  
. 7      Double m, n-, H, L;                   // POW () function requires participation and return values are the number of type double 
. 8  
. 9      the while ( . 1 ) {
 10  
. 11          the printf ( " enter height: \ n- " );
 12 is  
13 is          Scanf ( " % LF " , & m);            // must is lf%,% F will appear logical error, enter the strict distinction between f% lf and% 
14  
15          printf (" Please enter the number of times: \ n- " );
 16  
. 17          Scanf ( " % LF " , & n-);
 18 is  
. 19          H = m * POW ( 0.5 , n-);
 20 is  
21 is          L = m + m * (( . 1 -pow ( 0.5 , n-)) / 0.5 );
 22 is  
23 is          the printf ( " jump% .2f m, a total length of motion% .2f m \ n ------------------- \ n- " , H, L); // the output LF% and in most cases are equivalent F% 
24  
25      }
 26 is  
27      return  0 ;
 28  
29 }

 

Guess you like

Origin www.cnblogs.com/gougouwang/p/11401403.html