473,394 Members | 1,935 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,394 software developers and data experts.

Display the given number with commas.

i need some help with a c program im making.

For example: if nNum is 12345, the program should display 12,345
Aug 12 '13 #1
2 1388
Nepomuk
3,112 Expert 2GB
Hi Keith and welcome to bytes.com!

What have you tried so far? What is and what isn't working?
Aug 12 '13 #2
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. main()
  3. {
  4. int i,copy,no=0,input,a[100];//a[100] is for storing the values between commas you can also use malloc();
  5. printf("ENTER A NUMBER : ");
  6. scanf("%d",&input);
  7. /*for storing the values b/w commas*/
  8. copy=input;
  9. for(i=0;i<100;i++)
  10. {
  11. no++;
  12. a[i]=copy%1000;
  13. copy/=1000;
  14. if(copy<1)
  15.  goto out;
  16. }
  17. out :
  18. for(;no>0;)
  19. printf("%i,",a[--no]);
  20. printf("\b");//this statement is given so that the last comma is deleted
  21. }
Aug 12 '13 #3

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

Similar topics

3
by: Michael Charney | last post by:
I have a form where records are entered. I have turned off the built in record control. I created buttons to advance and go back through the records as well as an add new record button, but I also...
13
by: Kishor | last post by:
Hi Friends Please help me to write a C program to find the 5th (fifth) root of a given number. Ex:(1) Input : 32 Output : 5th root of 32 is 2 Ex:(1) Input : 243 Output : 5th root of 243 is...
2
by: Reddy | last post by:
Hi, How to check whether a given number is an integer Thanks, Reddy
11
by: gchiazx | last post by:
Hi, can someone send me the algorithm for finding the products of prime numbers from a given number? Thank You Gary.
17
by: scan87 | last post by:
Can somone please, please give me the solution for the following problem. I need to submit it on Monday. Write a global function called format, which formats numbers with a given number of decimal...
1
by: psbasha | last post by:
Hi, How to find the number of digits from a given number?. For example num = 23456 The number of digits are 5 num = 2311150
3
by: Lastknight | last post by:
Hi all, I am trying to display the number of views of our website... I have tried with this link, <img src="http://www.easycounter.com/counter.php?barani" border="0" alt="HTML Hit...
4
by: gaurav1983 | last post by:
i have to generate unique combinations of given number of digits entered by user eg: N=4 (0,1,2,3) output should be 0 1 2 3
15
by: shivpratap | last post by:
I m solving a problem to find the sum of divisors of a given number(the number is a large one),...i hv written the code bt it's exceding the time limit...hw can i reduce the time in such cases...pls...
2
by: Gordon Padwick | last post by:
I am developing an Access application using Access 2010 running under Windows 7. The database has some large tables containing many thousands of rows. I want to display the number of rows in these...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.