All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Just Math
Natural Problem (Posted on 2003-08-29) Difficulty: 3 of 5
The Natural Numbers are written successively as shown below:
12345678910111213141516..........., such that the 4th digit is '4' the 9th digit is '9' but the 11th digit is '0', the 15th digit '2', the 17th '3', and so on.
What is the 40,000th digit that appears in this list ?

See The Solution Submitted by Ravi Raja    
Rating: 2.0000 (3 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re(2): Agreed (with code) | Comment 5 of 10 |
(In reply to re: Agreed by SilverKnight)

Caveat: I don't know how to make this
text box preserve spaces, so the indentation is shot. Also, I know itoa would probably be faster than sprintf, but I'm lazy -- what's a microsecond or two anyway...

#include <stdio.h>
#include <stdlib.h>
#define TARGET 40000
main()
{
char s[50000], *cp, ss[10];
int i,j,len;
cp = s;
s[0]=0;
len=0;
for(i=1; len < TARGET+2 ; i++) {
sprintf(ss,"%d",i);
j=strlen(ss);
strcpy(cp,ss);
cp += j;
len += j;
}
printf("character %d = %c\n",TARGET,s[TARGET-1]);
}

  Posted by Brian Wainscott on 2003-08-29 14:55:54

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (15)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information