primes.c

# primes.c - Name Arria P Owlia Section 15735 Assignment 3...

This preview shows pages 1–3. Sign up to view the full content.

Sheet1 Page 1 /*********************************************************** /Name:Arria P. Owlia /Section:15735 /Assignment:3 /Purpose:To have some fun with primes /***********************************************************/ #include <stdio.h> #define MAX 32768 int a[MAX] = {0} short int b[4000] = {0} int i, j, n, R, div, currentPrime = 0, C = 0, x = 0, e = 0 void makeArray(int a[], short int b[], int n) { for (i = 3 { a[i] = 1 } for (i = 0 b[i] = 0 j=0 i=1 while (n>0) { i = currentPrime + 2 while (a[i] == 0)/* find smallest value of a[i] that is one (is prime) */ { i++ } i-- b[j] = currentPrime = i j++ for (i = i+2 { if ((i-1)%currentPrime == 0) a[i] = 0 } n-- } } void printArray() { printf("\n") if (n<=8)/* If numbers to be displayed is less than 8, display without formatting */ { for (i = 0 printf("%5d ", b[i]) } else {

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Sheet1 Page 2 x=0 for (i = 0 { if (x < R)/* if column # is less than R, then print with normal incrementing */ printf("%5d ", b[((div+1)*x) + C]) else/* if greater than R, print with error correction */
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 12

primes.c - Name Arria P Owlia Section 15735 Assignment 3...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online