000001 #include <stdio.h>
000002 #include <stdlib.h>
000003 #include <errno.h>
000004 #include <string.h>
000005
000006 FILE *outputFile;
000007 char buffer[81];
000008 int bytesWritten;
000009
000010 main()
000011 {
000012 int isPrime(int);
000013
000014 int i,j;
000015
000016
000017 /*************************************/
000018 /* Open file to write output */
000019 /*************************************/
000020 outputFile = fopen("DD:OUTPUT", "w");
000021 if (outputFile == NULL)
000022 {
000023 printf("open error: %d/%s\n", errno, strerror(errno));
000024 exit(99);
000025 }
000026
000027 /*************************************/
000028 /* Run program */
000029 /*************************************/
000030
000031 for (i=1; i<15000; i++)
000032 {
000033 if (isPrime(i)==1)
000034 {
000035 bytesWritten = sprintf(buffer,"%d is prime!\n",i);
000036 fwrite(buffer, 1, bytesWritten, outputFile);
000037 }
000038 }
000039
000040 /*************************************/
000041 /* Close output file */
000042 /*************************************/
000043 fclose(outputFile);
000044
000045 return 0;
000046 }
000047
000048 int isPrime (int myInt)
000049 {
000050
000051 int loop;
000052
000053 for (loop = 2; loop < myInt/2+1; loop++)
000054 {
000055 if (myInt%loop==0)
000056 return 0;
000057 }
000058 return 1;
000059 }
000060
000002 #include <stdlib.h>
000003 #include <errno.h>
000004 #include <string.h>
000005
000006 FILE *outputFile;
000007 char buffer[81];
000008 int bytesWritten;
000009
000010 main()
000011 {
000012 int isPrime(int);
000013
000014 int i,j;
000015
000016
000017 /*************************************/
000018 /* Open file to write output */
000019 /*************************************/
000020 outputFile = fopen("DD:OUTPUT", "w");
000021 if (outputFile == NULL)
000022 {
000023 printf("open error: %d/%s\n", errno, strerror(errno));
000024 exit(99);
000025 }
000026
000027 /*************************************/
000028 /* Run program */
000029 /*************************************/
000030
000031 for (i=1; i<15000; i++)
000032 {
000033 if (isPrime(i)==1)
000034 {
000035 bytesWritten = sprintf(buffer,"%d is prime!\n",i);
000036 fwrite(buffer, 1, bytesWritten, outputFile);
000037 }
000038 }
000039
000040 /*************************************/
000041 /* Close output file */
000042 /*************************************/
000043 fclose(outputFile);
000044
000045 return 0;
000046 }
000047
000048 int isPrime (int myInt)
000049 {
000050
000051 int loop;
000052
000053 for (loop = 2; loop < myInt/2+1; loop++)
000054 {
000055 if (myInt%loop==0)
000056 return 0;
000057 }
000058 return 1;
000059 }
000060