Total members 11894 |It is currently Sat Nov 23, 2024 9:08 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Hi People,
I have a doubt in C program.
Suppose i have declared int i = 1234;
If I want to print only 12 (first 2 digits) using printf statement, please
suggest how do i implement it.




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

You can convert the int to a string with sprintf(), then truncate the
string after the first two characters, then display the string.

Alternatively, if you want to achieve a result of 12 mathematically,
you can use modulus (%) and division (/) :

(i - (i % 100)) / 100

== 12

_________________
Please recommend my post if you found it helpful


Author:
Proficient
User avatar Posts: 228
Have thanks: 0 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Format Specifier in C
 PDF Format     -  
 Format Debugging Messages     -  
 Number format for current     -  
 Number format function prototype     -  
 i want to draw a circle on a image(any format bmp,jpeg etc.)     -  
 Handling m3g format (3D files for mobiles) in J2ME     -  
 Printing today+ current date with different format     -  
 database contents display in table format in swing     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com