andrew clarke wrote: > On Mon 2008-09-01 02:02:24 UTC-0700, prakaashganth d ([EMAIL PROTECTED]) > wrote: > >> 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. > > 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
There is no need for subtracting the modulus. It is redundant. Integers are truncated automatically. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
