+ 2
Why this is not working?how to make it work?
Military time,code coach for converting 12 hour time input to 24 hour format. https://code.sololearn.com/c7Pd6UPme7vu/?ref=app
6 Respuestas
+ 1
When the width value is specified for an integer, it can be used to aligns to right in the output.
For example:
printf("%4d",value);
This statement ensures that the output for value is right-justified and at least four characters wide. If value is fewer than four characters wide, it’s padded with spaces on the left. That is, unless you stick a 0 in there:
printf("%04d",value);
In that case, the printf() function pads the width with zeros to keep everything four characters wide.
hope it clears..
+ 4
There it indicate to fill minimum of 2 digits width in output console and printing with 0 as appended left.
if you omit 0 then, it prints with 2 character width with space at left
observe this with printf("%22d", h);
edit:
see this for clear information: lesson 4.1
https://www.sololearn.com/learning/2914/
edit:gaurav kumar
link may have buggy.
pasting information:
#include <stdio.h>
int main() {
printf("Color: %s, Number: %d, float: %5.2f \n", "red", 42, 3.14159);
/* Color: red, Number: 42, float: 3.14 */
printf("Pi = %3.2f \n", 3.14159);
/* Pi = 3.14 */
printf("Pi = %8.5f \n", 3.14159);
/* Pi = 3.14159 */
printf("Pi = %-8.5f \n", 3.14159);
/* Pi = 3.14159 */
printf("There are %d %s in the tree. \n", 22, "apples");
/* There are 22 apples in the tree. */
}
+ 1
May this works..
printf("%02d%c%02d",hh,ch,mm);
Use capital Punishment instead of small.. Hope it helps...
+ 1
%02d why 0?i know only this %d or %2d.what is capital punishment ?
+ 1
Format specifiers begin with a percent sign % and are replaced by corresponding arguments after the format string. A format specifier can include several options along with a conversion character:
%[-][width].[precision]conversion character
The optional - specifies left alignment of the data in the string.
The optional width gives the minimum number of characters for the data.
The period . separates the width from the precision.
The optional precision gives the number of decimal places for numeric data. If s is used as the conversion character, then precision determines the number of characters to print.
The conversion character converts the argument, if necessary, to the indicated type:
d decimal
c character
s string
f float
e scientific notation
x hexadecimal
+ 1
Yes i know about this bro=%5.2d ,width,precision,etc.
But isn't
02=2
Why 0?.i didn't got now also.