Here is my situation. I have seen different snippets of C code but have never really learned to program in it. I have a piece of code that I need to analyze, then modify to produce a certain output. I am hoping that someone here can point me in the direction I need to go... I am totally lost with this. Here is the source :
Code:
01 #include <stdio.h>
02 #include <stdlib.h>
03 #include <errno.h>
04 #include <string.h>
05
06 FILE *outputFile;
07 char buffer[81];
08 int bytesWritten;
09
10 main()
11 {
12 int isPrime(int);
13
14 int i,j;
15
16
17 /*************************************/
18 /* Open file to write output */
19 /*************************************/
20 outputFile = fopen("DD:OUTPUT", "w");
21 if (outputFile == NULL)
22 {
23 printf("open error: %d/%s\n", errno, strerror(errno));
24 exit(99);
25 }
26
27 /*************************************/
28 /* Run program */
29 /*************************************/
30
31 for (i=1; i<15000; i++)
32 {
33 if (isPrime(i)==1)
34 {
35 bytesWritten = sprintf(buffer,"%d is prime!\n",i);
36 fwrite(buffer, 1, bytesWritten, outputFile);
37 }
38 }
39
40 /*************************************/
41 /* Close output file */
42 /*************************************/
43 fclose(outputFile);
44
45 return 0;
46 }
47
48 int isPrime (int myInt)
49 {
50
51 int loop;
52
53 for (loop = 2; loop < myInt/2+1; loop++)
54 {
55 if (myInt%loop==0)
56 return 0;
57 }
58 return 1;
59 }
60
Now, here is the out put that is necessary:
Bob's Palindromic Primes
(insert a blank line between header and first line of print)
Prime number 2 is also a Palindrome
Prime number 3 is also a Palindrome
Prime number 5 is also a Palindrome
Prime number 7 is also a Palindrome
Prime number 11 is also a Palindrome
Prime number 101 is also a Palindrome (etc. keeps repeating with primes that are palindromes)
Here is some information that may be of help to you: The range of numbers to find primes palindromes is to be hard coded, not prompted for input from the user. Also, a JCL script is ran against this source member to generate the output to another member. I appreciate your time, any little bit may help. Thanks.