Question

All the digits to massive Mersenne primes are contained in text files. Your job is to...

All the digits to massive Mersenne primes are contained in text files. Your job is to write a java program that takes one of these text files as a command line argument and displays how many times each digit appears in the prime number as well as the total number of digits. ZIP files containing such text files can be found at: http://www.mersenne.org/primes/. For example, the most recently discovered Mersenne prime can found at: http:// www.mersenne.org/primes/digits/M74207281.zip. You'll need to download the ZIP file and unzip it to access the text file. Sample Run: Command Prompt$ ./a.out M74207281.txt 0s: 2233259 1s: 2233437 2s: 2234193 3s: 2232135 4s: 2232328 5s: 2236279 6s: 2234254 7s: 2233628 8s: 2234257 9s: 2234848 Total: 22338618

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

#include <string.h>

int main(int argc, char *argv[])

{

FILE *fp;

char fileName[50];

strcpy(fileName,argv[1]);

printf("%s\n", fileName);

fp = fopen(fileName, "r");

long digitCounter[10], total = 0;

char c;

for(int i = 0; i < 10; i++)

digitCounter[i] = 0;

while((c = getc(fp)) != EOF)

{

total++;

digitCounter[c-'0']++;

}

for(int i = 0; i < 10; i++)

printf("%is: %li\n", i, digitCounter[i]);

printf("Total: %li\n", total);

}

===================================
See Output
kundrar--bash_ 80x24 [c4b301bb9697:~ kundrar$ ./a.out M74207281.txt M74207281.txt 0s: 2233259 1s: 2233437 2s: 2234193 3s: 223


Thanks, PLEASE UPVOTE if helpful

Add a comment
Know the answer?
Add Answer to:
All the digits to massive Mersenne primes are contained in text files. Your job is to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT