Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > sob..Someone can help me????plsss

Reply
Thread Tools

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

 
 
aslamhenry@yahoo.com
Guest
Posts: n/a
 
      09-20-2007
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

 
Reply With Quote
 
 
 
 
aslamhenry@yahoo.com
Guest
Posts: n/a
 
      09-20-2007
On Sep 20, 2:39 pm, (E-Mail Removed) 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;
>
> 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

On Sep 20, 2:39 pm, (E-Mail Removed) 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;
>
> 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





 
Reply With Quote
 
 
 
 
Army1987
Guest
Posts: n/a
 
      09-20-2007
On Wed, 19 Sep 2007 23:39:27 -0700, aslamhenry 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()

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.

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

 
Reply With Quote
 
aslamhenry@yahoo.com
Guest
Posts: n/a
 
      09-20-2007
On Sep 20, 7:10 pm, Army1987 <(E-Mail Removed)> wrote:
> On Wed, 19 Sep 2007 23:39:27 -0700, aslamhenry 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()

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

 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      09-20-2007
On Sep 20, 8:02 am, (E-Mail Removed) wrote:
> On Sep 20, 7:10 pm, Army1987 <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Wed, 19 Sep 2007 23:39:27 -0700, aslamhenry 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()

>
> > 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=...=Google+Search

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-20-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:
[...]
> 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);

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
aslamhenry@yahoo.com
Guest
Posts: n/a
 
      09-20-2007
On Sep 20, 2:39 pm, (E-Mail Removed) 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;
>
> 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...



 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-20-2007
(E-Mail Removed) wrote:
>

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

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      09-20-2007
On Thu, 20 Sep 2007 18:35:43 -0400, CBFalconer wrote:

> 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.
--
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

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      09-21-2007
(E-Mail Removed) wrote:
>
> On Sep 20, 2:39 pm, (E-Mail Removed) 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;
> >
> > 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...


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;
}

--
pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wireless can get internet but can't see network -- can when wired 02befree Computer Support 0 12-24-2007 09:10 PM
SOLVED - can't open file in windows media player / WMP. But can in VLC - video LAN .. Now can in WMP jameshanley39@yahoo.co.uk Computer Information 2 09-19-2007 02:53 AM
Where can I find the help I need ? Can you help ? penang@catholic.org Computer Support 8 06-09-2007 02:55 PM
ReQ; Help having problem with cisco router 1602R the Lan part works cannot log on to configure so PC can access internet, router connects to T1 line thier is an alarm light on anyone can help smokin@aol.com Computer Support 4 10-30-2004 06:06 AM
Nothing can be found... HELP HELP HELP ... -=zZz=- Computer Support 15 02-29-2004 10:47 PM



Advertisments