Sat Nov 08, 2008 11:10 pm
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.
Sat Nov 08, 2008 11:11 pm
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
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
Powered by phpBB © phpBB Group.