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
#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
Thanks, PLEASE UPVOTE if helpful
All the digits to massive Mersenne primes are contained in text files. Your job is to...