sob..Someone can help me????plsss

A

aslamhenry

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 when i put 56789...
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....

THX MUahhh
 
A

aslamhenry

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 when i put 56789...
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....

THX MUahhh
CORRECTION


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 when i put 56789...
but if i key in 12345 the program excute nicely.....

anyone can tell what wrong with my coding...

and i really appreciate if someone can make it more efficient....

THX MUahhh
 
A

Army1987

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()
main returns an int. See www.c-faq.com, question 1.25b.
{
int num;
float num1,num2,num3,num4;
float r1,r2,r3,r4;

printf("please key in any 5 digit number:");
scanf("%d",&num); [snip]
the problem occur when i entered nnumber 56789.It output become
rubbish when i put 56789...
but if i key in 12345 the program excute nicely.....

anyone can tell what wrong with my coding...
The maximum value guaranteed to fit in an int is 32767. Declare
num as a long (you'll need to use "%ld" instead of "%d").
By the way, there is absolutely no need to use floating point
here, integers would do it, or better still consider the input as
a string as you were told in the other thread.
Do like this:
read 6 characters from stdin;
if the first 5 characters are digits and the sixth is whitespace,
the input is ok; process it as you were told in the other thread;
else do something sensible. Note that scanf doesn't touch num if
it fails (e.g. there are no numeric data but letters or
punctuation or else), in which case num stays uninitialized. Don't
use scanf() unless there is no better choice. Hint: there always
is a better choice.
 
A

aslamhenry

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()

main returns an int. Seewww.c-faq.com, question 1.25b.
{
int num;
float num1,num2,num3,num4;
float r1,r2,r3,r4;
printf("please key in any 5 digit number:");
scanf("%d",&num); [snip]
the problem occur when i entered nnumber 56789.It output become
rubbish when i put 56789...
but if i key in 12345 the program excute nicely.....
anyone can tell what wrong with my coding...

The maximum value guaranteed to fit in an int is 32767. Declare
num as a long (you'll need to use "%ld" instead of "%d").
By the way, there is absolutely no need to use floating point
here, integers would do it, or better still consider the input as
a string as you were told in the other thread.
Do like this:
read 6 characters from stdin;
if the first 5 characters are digits and the sixth is whitespace,
the input is ok; process it as you were told in the other thread;
else do something sensible. Note that scanf doesn't touch num if
it fails (e.g. there are no numeric data but letters or
punctuation or else), in which case num stays uninitialized. Don't
use scanf() unless there is no better choice. Hint: there always
is a better choice.

--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid "Smart Quotes" feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen- Hide quoted text -

- Show quoted text -

how to use %ld??since im a newbie....there still a lot of coding that
ive never seen before
 
U

user923005

main returns an int. Seewww.c-faq.com, question 1.25b.
{
int num;
float num1,num2,num3,num4;
float r1,r2,r3,r4;
printf("please key in any 5 digit number:");
scanf("%d",&num); [snip]
the problem occur when i entered nnumber 56789.It output become
rubbish when i put 56789...
but if i key in 12345 the program excute nicely.....
anyone can tell what wrong with my coding...
The maximum value guaranteed to fit in an int is 32767. Declare
num as a long (you'll need to use "%ld" instead of "%d").
By the way, there is absolutely no need to use floating point
here, integers would do it, or better still consider the input as
a string as you were told in the other thread.
Do like this:
read 6 characters from stdin;
if the first 5 characters are digits and the sixth is whitespace,
the input is ok; process it as you were told in the other thread;
else do something sensible. Note that scanf doesn't touch num if
it fails (e.g. there are no numeric data but letters or
punctuation or else), in which case num stays uninitialized. Don't
use scanf() unless there is no better choice. Hint: there always
is a better choice.
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid "Smart Quotes" feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen- Hide quoted text -
- Show quoted text -

how to use %ld??since im a newbie....there still a lot of coding that
ive never seen before

Suggestion:
Invest in a C book if you want to learn C.
Try K&R2:
http://cm.bell-labs.com/cm/cs/cbook/

Meanwhile, try a google search like:
http://www.google.com/search?client...hannel=s&hl=en&q=man+scanf&btnG=Google+Search
 
K

Keith Thompson

how to use %ld??since im a newbie....there still a lot of coding that
ive never seen before

Please trim quoted text when you post a followup. Quote just enough
of the parent article so your response makes sense on its own. It's
rarely necessary to quote the whole thing.

Using "%ld" is a very elementary part of using printf. If your
textbook is any good, you should be able to find the answer there.

But I'll show you a quick example anyway:

int x = 12345;
long y = 12345678;
printf("x = %d, y = %ld\n", x, y);
 
A

aslamhenry

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 when i put 56789...
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....
ceh my teacher is totally jerk........now he ask me to do in looping
humm.....i think maybe i can use for...nvm i will try to do on my
own...
i will ask if got any prob....
i think must use nested for...
 
C

CBFalconer

.... snip ...

ceh my teacher is totally jerk........now he ask me to do in looping
humm.....i think maybe i can use for...nvm i will try to do on my
own...
i will ask if got any prob....
i think must use nested for...

What are all those dots for? Sentences are normally terminated
with a period (one dot) followed by two spaces. Sentences are
normally commenced with an upper case letter. All this greatly
improves readability. Other possible sentence terminating
punctuation marks include '!' and '?'. After you get those
straight start thinking about comma, colon, and semi-colon. But
start with period (the one dot).
 
A

Army1987

What are all those dots for? Sentences are normally terminated
with a period (one dot) followed by two spaces.
Not by everybody. Many people follow it with one space.
 
P

pete

ceh my teacher is totally jerk........now he ask me to do in looping
humm.....i think maybe i can use for...nvm i will try to do on my
own...
i will ask if got any prob....
i think must use nested for...

It's really a string problem and not a math problem.

/* BEGIN new.c */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define LENGTH 5
#define str(x) # x
#define xstr(x) str(x)

int main(void)
{
int rc;
char array[LENGTH + 1];
size_t index, space, loop;

fputs("please key in any 5 digits number :", stdout);
fflush(stdout);
rc = fscanf(stdin, "%" xstr(LENGTH) "[^\n]%*[^\n]", array);
if (!feof(stdin)) {
getc(stdin);
}
if (rc == 0) {
array[0] = '\0';
}
if (rc == EOF) {
puts("rc equals EOF");
exit(EXIT_FAILURE);
}
for (index = 0; index != sizeof array - 1; ++index) {
if (isdigit((unsigned char)array[index]) == 0) {
puts("isnum(array[index]) == 0");
exit(EXIT_FAILURE);
}
}
space = 0;
for (loop = sizeof array - 2; loop != 0; --loop) {
for (index = space; index != 0; --index) {
putchar(' ');
}
for (space += 2; index != loop; ++index) {
putchar(array[index]);
}
putchar(' ');
putchar(' ');
puts(array + index);
}
return 0;
}
 
P

pete

It's really a string problem and not a math problem.

/* BEGIN new.c */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define LENGTH 5
#define str(x) # x
#define xstr(x) str(x)

int main(void)
{
int rc;
char array[LENGTH + 1];
size_t index, space, loop;

fputs("please key in any 5 digits number :", stdout);

I like this better:

printf("please key in any " xstr(LENGTH) " digits number :");
 
R

Richard Heathfield

Army1987 said:
Not by everybody. Many people follow it with one space.

The two-space gap between sentences goes back to typewriting with a
fixed-pitch font. It was considered to be more aesthetically pleasing than
a single space, although really two spaces was a little too much (but one
space wasn't quite enough!). With the advent of smart word processors that
could put an aesthetically decent gap between one sentence and the next,
given only the hint of a full stop and a space, the practice faded out,
even in Usenet, where fixed-pitch fonts are the norm (presumably because
many people do more typing in word processors or other programs with
proportional fonts than in fixed-pitch programs such as text editors and
good Usenet clients).

I've been using one space as a sentence separator for so long that I cannot
now remember when I made the switch from two spaces.

I'm trying to think up a way to link this to C, but not having a great deal
of success.
 
R

Richard Bos

CBFalconer said:
What are all those dots for? Sentences are normally terminated
with a period (one dot) followed by two spaces.

One space, in civilised countries.

Richard
 
F

Flash Gordon

Richard Heathfield wrote, On 21/09/07 01:52:
Army1987 said:


The two-space gap between sentences goes back to typewriting with a
fixed-pitch font. It was considered to be more aesthetically pleasing than
a single space, although really two spaces was a little too much (but one
space wasn't quite enough!). With the advent of smart word processors that
could put an aesthetically decent gap between one sentence and the next,
given only the hint of a full stop and a space, the practice faded out,
even in Usenet, where fixed-pitch fonts are the norm (presumably because
many people do more typing in word processors or other programs with
proportional fonts than in fixed-pitch programs such as text editors and
good Usenet clients).

I've been using one space as a sentence separator for so long that I cannot
now remember when I made the switch from two spaces.

I'm trying to think up a way to link this to C, but not having a great deal
of success.

You could write a filter program in standard C to adjust your posts so
that they use two spaces.
 
A

Army1987

I like this better:

printf("please key in any " xstr(LENGTH) " digits number :");
If you are indeed using printf, what's wrong with
printf("please key in any %d digits number :", (int)LENGTH)?
It'll continue to work if you define LENGTH in some more insane way.
 
A

Army1987

You could write a filter program in standard C to adjust your posts so
that they use two spaces.

It is less trivial than it seems, Mr. Foo would receive two
spaces, too. (The solution could be using an extensive list of all
abbreviations such as Mr. etc. which can be followed by a capital
letter without starting a new sentence... But maybe there are
ambiguities, there, too?
And what about cases such as a proper name immediately followed by
ellipses? Ellipses are always three dots, they don't become four
when they end a sentence, usually the only way to tell if they do
is the case of the following letter...)

Anyway, a program written in C which uses ". " to tell where a
sentence finishes would be broken by using ". ".
 
A

Al Balmer

even in Usenet, where fixed-pitch fonts are the norm (presumably because
many people do more typing in word processors or other programs with
proportional fonts than in fixed-pitch programs such as text editors and
good Usenet clients).

Since we're off-topic anyway, I wonder if this is actually true? I
read Usenet in a proportional font simply because I find it easier to
read. I switch to a fixed font when someone posts code, or underlines
an non-obvious part of the previous sentence. I consider my Usenet
client to be a good one. In fact, the ability to switch fonts is one
of its good features :)
 
W

Walter Roberson

Since we're off-topic anyway, I wonder if this is actually true?

Who knows? Unless someone cares to do a statistical study of the
X-Newsreader headers of a large number of posts, and trusts that
the newsreaders are not lying about what program they are, and
the Newsreader name is correlated to ability to change fonts... then
the matter is essentially undecideable, potentially amenable only to
polls with bad "self-selection" bias.

And even if someone bothers to look up my X-Newsreader header and
notices that it cannot change fonts, they would miss the fact that I'm
almost always running the newsreader inside a terminal window and that
the terminal window can be configured to any font I want.

But if anyone cares: *I* only use fixed-width for reading Usenet.
I scan too many messages in which the formatting is important
(e.g., code) to make it worth flipping back and forth between
fonts.
 
F

Flash Gordon

Army1987 wrote, On 21/09/07 14:22:
It is less trivial than it seems, Mr. Foo would receive two

<snip difficulties>

I did not say that it was easy. Perhaps it would make good coursework
with extra marks being given for each of the difficulties the student
raises?
Anyway, a program written in C which uses ". " to tell where a
sentence finishes would be broken by using ". ".

I was not suggesting that a program should do that.
 
C

CBFalconer

Army1987 said:
. snip ...


It is less trivial than it seems, Mr. Foo would receive two
spaces, too. (The solution could be using an extensive list of all
abbreviations such as Mr. etc. which can be followed by a capital
letter without starting a new sentence... But maybe there are
ambiguities, there, too?
And what about cases such as a proper name immediately followed by
ellipses? Ellipses are always three dots, they don't become four
when they end a sentence, usually the only way to tell if they do
is the case of the following letter...)

Anyway, a program written in C which uses ". " to tell where a
sentence finishes would be broken by using ". ".

Hey, I just wrote a sentence advising aslamhenny how to properly
punctuate English sentences; I didn't expect a major upheaval from
it. (And they don't end with ....).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top