Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
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.
AnswerBot
Question subject: Re: Format Specifier in C
Posted: Sat Nov 08, 2008 11:11 pm
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 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 (/) :