Thursday, July 30, 2009

How does one display % sign as part of string in C language?

two ways:


1. use escape sequence \%


2. write twice % sign


e.g.


1. printf("I got 79.3%%");


2. printf("I got 79.3\%");

How does one display % sign as part of string in C language?
u have to enter the % symbol within the double quotes
Reply:printf("printing %% here ");





Output: printing % here





Trick: Just use %% to print % in any printf statement...
Reply:There is 'Escape Sequence' for this puprose...


To write special characters you need to put an escape charatcer '\' (backslash) before it.


e.g.





% \%


\ \\


etc.
Reply:printf("%");
Reply:printf("The Percent Sign is: \%");
Reply:"escape it"


like this: \%
Reply:The answer is already out there.... use the escape char "\"


printf("I got 90\%"); gives I got 90%
Reply:%%


No comments:

Post a Comment