Velocity Reviews > plz send me the solution of the problem.

# plz send me the solution of the problem.

wahid
Guest
Posts: n/a

 01-09-2010
Write a program that will have an integer
number input, and show the digits seperately.
(Assume that no number with more than 3
digits will be present in the input)

like :
• Enter a Number: 942
• The first digit of the number is : 9
• The second digit of the number is : 4
• The third digit of the number is : 2

Doug Miller
Guest
Posts: n/a

 01-09-2010
In article <(E-Mail Removed)>, wahid <(E-Mail Removed)> wrote:
>Write a program that will have an integer
>number input, and show the digits seperately.
>(Assume that no number with more than 3
>digits will be present in the input)
>
>like :
>=95 Enter a Number: 942
>=95 The first digit of the number is : 9
>=95 The second digit of the number is : 4
>=95 The third digit of the number is : 2

Please post your professor's email address so we can send the program directly
to him.

Or do your own ****ing homework.

Chad
Guest
Posts: n/a

 01-09-2010
On Jan 9, 9:39*am, (E-Mail Removed) (Doug Miller) wrote:
> In article <(E-Mail Removed)..com>, wahid <(E-Mail Removed)> wrote:
>
> >Write a program that will have an integer
> >number input, and show the digits seperately.
> >(Assume that no number with more than 3
> >digits will be present in the input)

>
> >like :
> >=95 Enter a Number: 942
> >=95 The first digit of the number is : 9
> >=95 The second digit of the number is : 4
> >=95 The third digit of the number is : 2

>
> Please post your professor's email address so we can send the program directly
> to him.
>
> Or do your own ****ing homework.

Okay, it took me an entire 45 seconds to come up with a solution. What
do I win?

osmium
Guest
Posts: n/a

 01-09-2010
wahid wrote:

> Write a program that will have an integer
> number input, and show the digits seperately.
> (Assume that no number with more than 3
> digits will be present in the input)
>
> like :
> • Enter a Number: 942
> • The first digit of the number is : 9
> • The second digit of the number is : 4
> • The third digit of the number is : 2

In elemntary school you learned how to divide integers and then later on you
discovered the wonders of "long division"; with integers, C follows the
rules from the earlier years. Use that hint to write your program.

Eric Sosman
Guest
Posts: n/a

 01-09-2010
On 1/9/2010 12:29 PM, wahid wrote:
> Write a program that will have an integer
> number input, and show the digits seperately.
> (Assume that no number with more than 3
> digits will be present in the input)
>
> like :
> • Enter a Number: 942
> • The first digit of the number is : 9
> • The second digit of the number is : 4
> • The third digit of the number is : 2

#include <stdio.h>
#include <stdlib.h>
int main(void) {
const char *fmt = "The first digit of the number is : %d\n"
"The second digit of the number is : %d\n"
"The third digit of the number is : %d\n";
int number;
if (scanf("%d", &number) != 1)
return EXIT_FAILURE;
switch (number) {
case 0: printf(fmt, 0, 0, 0); break;
case 1: printf(fmt, 0, 0, 1); break;
/* ... left as an exercise for the student ... */
case 999: printf(fmt, 9, 9, 9); break;
default: return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

Note: A C90 compiler might reject this program on the grounds
that it has too many case labels. The C99 Standard raised the
limit, and will not reject it for that reason. Try to find a C99-
conforming compiler, just for safety's sake.

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)lid

Antoninus Twink
Guest
Posts: n/a

 01-09-2010
On 9 Jan 2010 at 17:29, wahid wrote:
> like :
> â€¢ Enter a Number: 942
> â€¢ The first digit of the number is : 9
> â€¢ The second digit of the number is : 4
> â€¢ The third digit of the number is : 2

#include <stdio.h>

#define S1 "The "
#define S2 " digit of the number is : %d\n"

int main(void)
{
int d, rv = 0;
fputs("Enter a Number: ", stdout);
fflush(stdout);
if(scanf("%d", &d) == 1 && d >=0 && d <= 999)
printf(S1 "first" S2 S1 "second" S2 S1 "third" S2, d/100, d%100/10, d%10);
else {
fputs("Invalid input: needed a non-negative integer with <= 3 digits\n",
stderr);
rv = 1;
}
return rv;
}

Seebs
Guest
Posts: n/a

 01-09-2010
On 2010-01-09, wahid <(E-Mail Removed)> wrote:
> Write a program that will have an integer
> number input, and show the digits seperately.
> (Assume that no number with more than 3
> digits will be present in the input)

> like :
> ? Enter a Number: 942
> ? The first digit of the number is : 9
> ? The second digit of the number is : 4
> ? The third digit of the number is : 2

I'm surprised you're getting this as homework. It's surprisingly
difficult for homework to assign to someone who apparently has never
made any effor towards learning C. Anyway, here's something
you might try:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <stddef.h>
#include <math.h>

struct {
double lo, close;
int d;
} digits[] = {
{ 6.80183905339058814121, 6.80239476332431092231, '\x39' },
{ 6.68398653227400885157, 6.68461172766792710576, '\x38' },
{ 6.55036579410553621017, 6.55108033504340436792, '\x37' },
{ 6.39609597446756872330, 6.39692965521614631541, '\x36' },
{ 6.21360759808860851905, 6.21460809842219141785, '\x35' },
{ 5.99021376520632919949, 5.99146454710798170851, '\x34' },
{ 5.70211441755550385579, 5.70378247465620091816, '\x33' },
{ 5.29581423632991832307, 5.29831736654803631126, '\x32' },
{ 4.60015764416454686625, 4.60517018598809180219, '\x31' },
{ 9, 9, '\x30' },
{ 4.49423862528080952927, 4.49980967033026502122, '\x39' },
{ 4.37575702166028612794, 4.38202663467388120466, '\x38' },
{ 4.24132675257074609476, 4.24849524204935935501, '\x37' },
{ 4.08597631255158422192, 4.09434456222210041432, '\x36' },
{ 3.90197266957464483639, 3.91202300542814596085, '\x35' },
{ 3.67630067190707610081, 3.68887945411393625150, '\x34' },
{ 3.38439026334577430788, 3.40119738166215546116, '\x33' },
{ 2.97041446556970090143, 2.99573227355399085425, '\x32' },
{ 2.25129179860649530909, 2.30258509299404590109, '\x31' },
{ 9, 9, '\x30' },
{ 2.14006616349627076801, 2.19722457733621956422, '\x39' },
{ 2.01490302054226466666, 2.07944154167983574766, '\x38' },
{ 1.87180217690159134136, 1.94591014905531323187, '\x37' },
{ 1.70474809223842527217, 1.79175946922805495731, '\x36' },
{ 1.50407739677627416697, 1.60943791243410028180, '\x35' },
{ 1.25276296849536805667, 1.38629436111989057245, '\x34' },
{ 0.91629073187415510660, 1.09861228866810978211, '\x33' },
{ 0.40546510810816438486, 0.69314718055994528623, '\x32' },
{ -0.69314718055994528623, 0.00000000000000000000, '\x31' },
{ 9, 9, '\x30' },
{ NAN, NAN, '\x00' }
};

char *names[] = { "first", "second", "third", "oops", "****", 0 };

int
main(void) {
int n;
double d;
int i;
int hit = 0;
int di = 0;
printf("Enter a Number: ");
fflush(stdout);
if (scanf("%d", &n) != 1) {
fprintf(stderr, "Shyeah right.\n");
exit(EXIT_FAILURE);
}
d = sqrt(n);
if (d != d) {
fprintf(stderr, "**** you too buddy.\n");
exit(EXIT_FAILURE);
}
if ((d = log(n)) > 6.906 {
fprintf(stderr, "Yeah, well, your mama.\n");
exit(EXIT_FAILURE);
}

for (i = (d >= 0 ? 0 : (hit = 1, 20)); digits[i].lo == digits[i].lo; ++i) {
if (d > digits[i].lo) {
printf("The %s digit of the number is %c.\n",
names[di++], digits[i].d);
d = log(exp(d) - exp(digits[i].close));
hit = 2;
}
if (digits[i].lo == 9) {
if (hit == 1) {
printf("The %s digit of the number is %c.\n",
names[di++], digits[i].d);
}
if (hit) {
hit = 1;
}
}
}
return 0;
}

.... cut here...

Hope this helps!

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

sfuerst
Guest
Posts: n/a

 01-09-2010
On Jan 9, 10:23*am, "osmium" <(E-Mail Removed)> wrote:
> wahid wrote:
> > Write a program that will have an integer
> > number input, and show the digits seperately.
> > (Assume that no number with more than 3
> > digits will be present in the input)

>
> > like :
> > • Enter a Number: 942
> > • The first digit of the number is : 9
> > • The second digit of the number is : 4
> > • The third digit of the number is : 2

>
> In elemntary school you learned how to divide integers and then later on you
> discovered the wonders of "long division"; with integers, C follows the
> rules from the earlier years. *Use that hint to write your program.

Division? Who needs that?

#include <stdio.h>

int main(void)
{
unsigned n, x, y, m = 429496729;
char t[] = {48, 49, 50, 50, 51, 51, 52, 53, 53, 54, 55, 55, 56, 56,
57, 48, 23, 59, 41};
char *p = 16 + t;

printf("Enter a number less than 1000\n");
scanf("%u", &n);

x = (n >> 1) + (n >> 2);
y = (n >> 1) + (n >> 3) + (n >> 6) - (n >> 10) + (x >> 11) - (n >>
16);
x += x >> 4;
x += x >> 8;
y += y >> 20;
x += x >> 16;
y >>= 6;
*p++ = ((m * n) >> 2[t];
x >>= 3;
*p++ = ((m * ((n > 9 + x * 10) + x)) >> 2[t];
*p = ((m * ((n > 99 + y * 100) + y)) >> 2[t];

printf("The first digit of the number is %c\n", *p--);
printf("The second digit of the number is %c\n", *p--);
printf("The third digit of the number is %c\n", *p);

return 0;
}

wahid
Guest
Posts: n/a

 01-10-2010
thank you .

Chad
Guest
Posts: n/a

 01-10-2010
On Jan 9, 6:53*pm, pete <(E-Mail Removed)> wrote:
> wahid wrote:
> > Write a program that will have an integer
> > number input, and show the digits seperately.
> > (Assume that no number with more than 3
> > digits will be present in the input)

>
> > like :
> > Enter a Number: 942
> > The first digit of the number is : 9
> > The second digit of the number is : 4
> > The third digit of the number is : 2

>
> /* BEGIN new.c */
>
> #include <stdio.h>
>
> #define MAX * * * * * * 999
> #define str(x) * * * * *# x
> #define xstr(x) * * * * str(x)
>
> int main(void)
> {
> * * *int d;
> * * *char array[sizeof xstr(MAX)];
> * * *char *string[] = {"first","second","third"};
>
> * * *fputs("Enter an integer from 0 to " xstr(MAX) ": ", stdout);
> * * *fflush(stdout);
> * * *if (fscanf(stdin, "%d", &d) == 1 && d >= 0 && MAX >= d) {
> * * * * *sprintf(array, "%d", d);
> * * * * *for (d = 0; array[d] != '\0'; ++d) {
> * * * * * * *printf("The %-6s digit of the number is : %c\n",
> * * * * * * * * *string[d], array[d]);
> * * * * *}
> * * *} else {
> * * * * *puts("Try again.");
> * * *}
> * * *return 0;
>
> }
>
> /* END new.c */
>
> --
> pete

Not to sound like a dick. But whatever happened to waiting for the
person to post an attempted solution before posting a (correct) one?

 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 OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post mrkanuganti@gmail.com C++ 2 11-24-2006 11:33 AM mrkanuganti@gmail.com C++ 1 11-24-2006 10:23 AM brian C Programming 7 11-25-2004 01:30 AM alkzy Microsoft Certification 0 10-31-2004 10:04 PM Nick Computer Support 0 06-04-2004 08:50 PM

Advertisments