473,320 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Printing a integer variable using putchar()

Sir please consider the following question and code.
1) printing a integer variable 'a' having value less than 1000.
putchar( (a/100) + ' 0 ' );
a=a%100;
putchar( (a/10) + ' 0 ' );
a=a%10;
putchar(a + ' 0 ' );
Could you please explain the above.
Thank you.
Jan 30 '07 #1
1 10503
willakawill
1,646 1GB
Sir please consider the following question and code.
1) printing a integer variable 'a' having value less than 1000.
putchar( (a/100) + ' 0 ' );
a=a%100;
putchar( (a/10) + ' 0 ' );
a=a%10;
putchar(a + ' 0 ' );
Could you please explain the above.
Thank you.
Hi. putchar takes an integer as a parameter and prints the ascii character for that value. a/100 is an integer division and will be 1 for all numbers of 100 and above. It will be 0 for numbers below 100.
+ '0' will be an integer addition of the value of the char '0' which is 48 and the division a/100.
Therefore, if a is 100 or greater the result is 1 + 48 or 49 which is the character '1'

If, for example, a == 123 then the next part is a modulus of a % 100 which is 23
23 / 10 is 2 and 2 + '0' is 50 which is the char 2

a % 10 or 23 % 10 is 3
3 + '0' or 3 + 48 is 51 which is the character 3
Jan 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: NickB | last post by:
Please could someone tell me what is wrong. Ther error is: An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll Additional information: Object...
3
by: Yammy Hung | last post by:
How to print out an integer (int) in C language without using printf()? Thanks in advance!
2
by: silly | last post by:
/*Thanks again to thos who helped with my 'more hand written integer pow() functions (LONG POST)' query. I needed to write a function to write out integers and after looking at some stuff on...
42
by: Prashanth Badabagni | last post by:
Hi, Can any body tell me how to print "hello,world" with out using semicolon Thanks in advance .. Bye Prashanth Badabagni
10
by: ben | last post by:
i'm learning about the floating point format that's used on my computer (apple mac so powerpc) i've written a function to print out the bits in a float to see how floats are represented and i...
10
by: Matt | last post by:
Ok, so the exercise is to: Write a program that prints its input one word per line. Does this mean so that when I prest ^Z(ctrl-z) to exit the program if I were to do this: Hey you It...
7
by: Amirallia | last post by:
Hello! I have a wecontrol table in a page, this table has a number of variable rows depending of the choice of the user. But when the table has a large number of rows, the printing of the page...
6
by: Bill | last post by:
Hi I am trying to get my listbox items to print if they stream past the one page mark. my code is working for one page of information (if the e.hasmorepages) is not there. But I am having...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.