DO NOT MISS

Ads

Sunday 10 July 2016

Format Specifiers, Conversions & Outputs


%w.p Specifier:-
Where ‘w’ is an integer number that specifies that total no of columns to are the output value and ‘p’ is another integer number that specifies the no of digits to the right of decimal point (of a real numbers) or the no of characters to be printed from a string.

%wd :- For printing an integer number.

Printing an integer numbers
Action
Output
 (Left & Right Alignment)
printf(%d\n”,6724);
6 7  2 4
printf(%6d\n”,6724);
       6 7  2 4
printf(%10d\n”,6724);
                     6 7 2 4
printf(%-6d\n”,6724);
6 7  2 4 0 0        
printf(%-10d\n”,6724);
6 7  2 4 0 0 0  0 0 0          
printf(%2d\n”,6724);
6 7  2 4
printf(%06d\n”,6724);
0 0 6 7  2 4
printf(%010d\n”,6724);
0  0 0 0 0 0 6 7  2 4

“-0” are Known as flags. 


%w.pf :- For printing real numbers. 

%w.pe:- For printing real numbers in exponential form. 

Example :- y=98.7654


Printing real numbers
Action
Output 
 (Left & Right Alignment)
Printf(“%7.4f\n”,y);
9 8  .  7 6 5 4
Printf(“%7.2f\n”,y);
9 8  .  7 7 
Printf(“%-7.2f\n”,y);
9 8  . 7  7
Printf(“%f\n”,y);
9 8  .  7 6 5 4  0  0           
Printf(“%-10.2f\n”,y);
9 8  .  7 7 _______
Printf(“%10.2f\n”,y);
0 0 0 0  0 9 8  .  7  7
Printf(“%11.4f\n”,y);
9 8  .  7 6 5  4 0 0 0 0
Printf(“%11.2f\n”,y);
9 8  .  7 7 0  0 0 0 0 0

%wc:- For printing a single character. 
The default value for w is ‘1’ 

%w.ps:- For printing strings. 
Where w specifiers the field width for display & P instructs that only first ‘P’ char’s of the string are to be displayed. 

Example:-“NEW DELHI 110001”

Printing strings
Action
Output (Left & Right Alignment)
%s
N E W  D E L H I  1 1 0 0 0 1
%20s
              N EW    D E L H  I     1 1  0 0 0 1
%20.10s
                                   N EW    D E L H  I 0
%-20.10s
N EW    D E L  H I  0 0 0 0 0 0 0 0 0 0 0  
%.5s
N EW    D
%5s
N EW    D E L H  I     1 1  0 0 0 1

Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims