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

Discuss..thx

please key in any 5 digits number : 56789

and the ouput is
5678 9
567 89
56 789
5 6789
how to write those program......
my idea is like this...
#include <stdio.h>
void main()
{
int num;
float num1,num2,num3,num4;
float r1,r2,r3,r4;
printf("please key in any 5 digit number:");
scanf("%d",&num);
num1=num/10;
num2=num/100;
num3=num/1000;
num4=num/10000 ;
r1=num%10;
r2=num%100 ;
r3=num%1000 ;
r4=num%10000 ;
printf("\n %.0f %.0f",num1,r1);
printf(" \n %.0f %.0f",num2,r2);
printf(" \n %.0f %.0f",num3,r3);
printf(" \n %.0f %.0f",num4,r4);
}
__________________________________________________ _________________________*
___

the problem occur when i entered nnumber 56789.It output become
rubbish..
but if i key in 12345 the program excute nicely.....
anyone can tell what wrong with my coding...
and i really appriciate if someone can make it more efficient....

Sep 20 '07 #1
1 1333
as********@yahoo.com wrote:
please key in any 5 digits number : 56789

and the ouput is
5678 9
567 89
56 789
5 6789
how to write those program......
my idea is like this...
#include <stdio.h>
void main()
{
int num;
float num1,num2,num3,num4;
float r1,r2,r3,r4;
Change 'float' to 'int' and the formats to %i.
>

printf("please key in any 5 digit number:");
scanf("%d",&num);
num1=num/10;
num2=num/100;
num3=num/1000;
num4=num/10000 ;
r1=num%10;
r2=num%100 ;
r3=num%1000 ;
r4=num%10000 ;
printf("\n %.0f %.0f",num1,r1);
printf(" \n %.0f %.0f",num2,r2);
printf(" \n %.0f %.0f",num3,r3);
printf(" \n %.0f %.0f",num4,r4);
}
__________________________________________________ _________________________*
___

the problem occur when i entered nnumber 56789.It output become
rubbish..
Could it be that your 'int' has only 16 bits? Then the largest number
it is going to handle is 32767.
but if i key in 12345 the program excute nicely.....
anyone can tell what wrong with my coding...
and i really appriciate if someone can make it more efficient....
Efficient? Your code is efficient enough. It's not generic enough,
so it can't do the same output for any number (two-digit to fifty-digit
ones, for example), but that's not the goal, right?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 20 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: SeeBelow | last post by:
This post is somewhat off topic, but I know of no better place to post it! SourceForge is often mentioned here. SourceForge itself hosts thousands of forums, but none of them (AFAIK) are for...
0
by: David Ascher | last post by:
In order to centralize discussion and minimize spam, we've created a new mailing list to discuss the Google Summer of Code from a Python POV. I strongly encourage people interested in discussing...
2
by: Ken North | last post by:
There will be a panel discussion on March 15 that's a special event at Software Development 2004 -- it's free to anyone who pre-registers for an expo pass. "Software Trends: Marrying SQL, XML,...
0
by: tom mccurdy | last post by:
Greetings, There has been a new site created www.quantumninja.com/toe that is to be used as a resource for people researching the theory of everything. Please join the community then use what is...
0
by: emac | last post by:
What is the best group to discuss ASP.NET 2.0 and/or 2.0 / VS in general?? Thanks all! emac@online.nospam
0
by: D. K. Mishra | last post by:
I am trying to author some MathMl pages. I have created some pages using some templates that I got from Design Science's web site. The pages work fine in both Internet Explorer 6.0 using Mathplayer...
0
by: Jason Huang | last post by:
Hi, Are there some ones familiar with the YetAnotherForum? I had problems in setting up the discuss forum using source provided by the YetAnotherForum. Thanks for help. Jason
2
dmjpro
by: dmjpro | last post by:
Hi Experts ....... I want to discuss ASPECTJ over here. Is it the right place to discuss? If it is then please reply. As soon as I ll get the reply then I ll start posting my problems. So...
0
by: Guilherme Polo | last post by:
On Sat, Sep 20, 2008 at 4:10 PM, dmitrey <dmitrey15@ukr.netwrote: It is not only the button that doesn't respond, the entire application won't respond if you are blocking tcl from processing...
0
by: Guilherme Polo | last post by:
On 10/29/08, Olrik Lenstra <o.lenstra@gmail.comwrote: It will be a combination of commands, not a single one. Initially I considered this as "probably without solution", since tcl acquired a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.