add a new example file
All checks were successful
MVS Upload & Execute / upload-and-run (push) Successful in 17s
All checks were successful
MVS Upload & Execute / upload-and-run (push) Successful in 17s
This commit is contained in:
parent
90455871aa
commit
155c57d4a6
5
jcl/SIEVE04.jcl
Normal file
5
jcl/SIEVE04.jcl
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//SIEVE03 JOB (GCC),'C Program Example',
|
||||||
|
// NOTIFY=@05054,CLASS=A,MSGCLASS=H,
|
||||||
|
// MSGLEVEL=(1,1),REGION=4M,TIME=1440
|
||||||
|
//STEP1 EXEC GCCCG,INFILE='@05054.SRCLIB.C(SIEVE03)'
|
||||||
|
//
|
46
src/SIEVE04.c
Normal file
46
src/SIEVE04.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
|
||||||
|
#define LIMIT 10000
|
||||||
|
#define PRIMES 1000
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int i,j,numbers[LIMIT];
|
||||||
|
int primes[PRIMES];
|
||||||
|
|
||||||
|
for (i=0;i<LIMIT;i++)
|
||||||
|
{
|
||||||
|
numbers[i]=i+2;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0;i<LIMIT;i++)
|
||||||
|
{
|
||||||
|
if (numbers[i]!=-1)
|
||||||
|
{
|
||||||
|
for (j=2*numbers[i]-2;j<LIMIT;j+=numbers[i])
|
||||||
|
numbers[j]=-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
for (i=0;i<LIMIT&&j<PRIMES;i++)
|
||||||
|
if (numbers[i]!=-1)
|
||||||
|
primes[j++] = numbers[i];
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
printf("PRIME NUMBERS BETWEEN 1 AND %d\n",LIMIT);
|
||||||
|
printf("TOTAL PRIMES FOUND: %d\n\n",PRIMES);
|
||||||
|
printf("LIST OF PRIMES:\n\n");
|
||||||
|
|
||||||
|
for (i=0;i<PRIMES;i++)
|
||||||
|
if (i % 20 == 0)
|
||||||
|
{
|
||||||
|
printf("\n %4d ",primes[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("%4d ",primes[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user