Arrays and functions? (easy question)
Code:
#include "stdafx.h"
#define size 100
int countPrimes(int,int);
int main()
{
/* Declaration of Variables */
int arr[size], i, j=1, remainder, primecount=0, max=size;
/* Fill the array with numbers 1 through the max size (100) */
for(i = 0;i < size; i++)
{
arr[i] = j++;
}
for(j = 2; j <= size; j++)
{
for(i = j; i < size; i++)
{
remainder = arr[i] % j;
/* If the number is not prime, set it to a 0. */
if(remainder == 0)
arr[i] = 0;
}
}
/* Count the prime numbers in the array */
for(int i=0;i<size;i++){
if (arr[i]!=0)
primecount++;
}
/* Print the array, not including the 0s. */
for(i = 0; i < size; i++)
{
if (arr[i]!=0)
printf("%d ",arr[i]);
}
/* Print the amount of prime numbers calculated. */
printf("\nThere are %d prime numbers up to %d.\n\n",primecount,max);
return 0;
}
I want to use functions for main, instead of doing everything inside of main.. I don't know how to pass arrays though... I want to just have like the functions, "arrayFiller", "primeChecker", "primeCounter", "arrayPrinter".... But how?