质数也成为素数,质数就是这个数除了1和他本身两个因数以外,没有其他因数的数,叫做质数,和他相反 的是合数,就是除了1和他本身两个因数以外,还友其他因数的数叫做合数。
- //以下为函数部分
- static void cal(long x)
- {
- long sum = 1;
- byte row = 1;
- Console.Write("\n");
- for (long a = 3; a < x + 1; a++)
- {
- bool flag = true;
- for (long b = 2; b < (a / 2) + 1; b++)
- {
- if (a % b != 0) continue;
- flag = false;
- break;
- }
-
- if (flag)
- {
- if (row == 10) {
- Console.WriteLine(); row = 0;
- }
- if (sum == 1)
- Console.Write("{0,7}", 2);
- Console.Write("{0,7}", a);
- sum++; row++;
- }
- }
- Console.WriteLine("\n\n{0} 以内共有 {1} 个质数\n", x, sum);
- }
- public static int Foo(int i)
- {
- if (i <= 0)
- return 0;
- else if (i > 0 && i <= 2)
- return 1;
- else
- return Foo(i - 1) + Foo(i - 2);
- }
- //冒泡排序类
- public class sorter
- {
- public void Sort(int[] list)
- {
- int i, j, temp;
- bool done = false;
- j = 1;
- while ((j < list.Length) && (!done))
- {
- done = true;
- for (i = 0; i < list.Length - j; i++)
- {
- if (list[i] > list[i + 1])
- {
- done = false;
- temp = list[i];
- list[i] = list[i + 1];
- list[i + 1] = temp;
- }
- }
- j++;
- }
- }
- }
- public int jiecheng(int n)
- {
- if (n == 1)
- return 1;
- else if (n == 2)
- return 2;
- else
- return n * jiecheng(n - 1);
- }
例如输⼊参数为整型数组{9,7,2},那么输出结果为字符串"9,7,2"。