0

After several hours I have figured this out, but because the % statement is confusing to me I was wondering if someone wolud not mind explaining to me my for statement in the following program?

```
using System;
/*This program is designed to identify the prime numbers from 1 to 100. Then total their sum and find the average of the prime numbers from 1 to 100.*/
public class PrimeNumbers
{
/* Main method entry point*/
public static void Main()
{
/*declare variables*/
int num = 2,
totalPrimeNum = 0,
x;
double countPrimeNum = 0,
avg;
/*while loop, which determines when num <= 100 (or 2 <= 100).*/
while (num <= 100)
{
bool isPrime = true;
/*test num to see if it is prime*/
for (x = 2; x < num; ++x)
{
if ((num % x) == 0)
{
isPrime = false;
break;
}
}
if(isPrime)
{
/* List the prime number, once the program determines a number is prime*/
Console.WriteLine (num);
countPrimeNum = countPrimeNum + num;
++totalPrimeNum;
}
//Add 1 to the number and then go to the begining of the loop and test to see wether to re-enter the loop or to go to the next step*/
++num;
}
avg = countPrimeNum / totalPrimeNum;
Console.WriteLine ("The average of the prime numbers between 2 to 100 is: {0}", avg);
}
}
```

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting