## format for floating point numeric input

3.format for floating point numeric input

%w.n f

Where w is the integer number specifying the total width of the input data and n spefies number of digits after decimal point .

Ex-

Scanf(“%3.11 %4.2f “,&a,&b);

Conditions-

(1) When input data length is less then the given length then the given values are unaltered and tored in the given variable .

Input: 5 5.9

Result :

5.0 is stored in a and 5.90 is stored in b.

(ii) when input data length is equal to the given length then the given values are unaltered and stored in the given variable .

Input:

5.3.5 92

Result: 5.3 is stored in a and 5.92 is stored in b.

(iii) when input data length is more than the given length then the give n values are altered and stored in the given variable as –

Input : 5.93 65.875

Result: 5.9 is stored in a and 3.00 is stored in b.

1. Format for floating point numeric output .

Where w is the integer number specifying the total width of the input data and n is the number of digits after decimal point.

Ex-printf(“%3.1 f %4.2 f”,a,b);

Ex-

Printf(“%3.1f %4.2f”,a,b)

Condition-

(i)When output data length is less than the given input data length

Input: 5 5.9

Output:

5.0 5.90

(ii) when output data length is equal to the data length

Input;5.3 5.92

Output:

5.3 5.92

(iii) when output data length is more than the given input length then digits after decimal point are truncated.

Input:

5.93 65.875

Output:

5.9 65.8

5.format for string input

%w.ns

Where w is the total number of characters in the string,decimal point and ‘n’ are optional .If present then (w-n) number of loasing blanks are interested before string.

Ex-

char str[8]

scanf (“%7s”,str);

condition

(i)when input string less than then the size of the arry

Input:-

Manju

Result:

‘m’ ‘a’ ‘n’ ‘j’ ‘u’\ 0 is stored in array str .

‘\0’ is automatically placed at the end of the string.

(ii) When the input string is equal to the size of the array.

Input : sanjeev

Result :

‘S’ ‘a’’n’ ‘j’ ‘e’ ‘e’ ‘v’ \0 is stored in array str

(iii) When the length of the input string is more tha n the size of the arrary then it can store the garbage value.

Print | posted on Friday, November 23, 2012 5:34 PM

## Feedback

No comments posted yet.