关于#c##的问题,请各位专家解答!

请编写函数 fun , 它的功能是 : 求出 1 到 100 之内能北 7 或者 11 整除 , 但不能同时北 7 和 11 整除的所有整数 , 并将他们放在 a 所指的数组中 , 通过 n 返回这些数的个数 。

这个用C#应该怎么写呢


class Program
{
    static void fun(int[] a, ref int n)
    {
        n = 0;
        for (int i = 1; i <= 100; i++)
        {
            if ((i % 7 == 0 || i % 11 == 0) && !(i % 7 == 0 && i % 11 == 0))
            {
                a[n++] = i;
            }
        }
    }
    static void Main(string[] args)
    {
        int[] a = new int[100];
        int n = 0;
        fun(a, ref n);
        Console.WriteLine(n);
        for (int i = 0; i < n; i++)
        {
            Console.Write("{0} ", a[i]);
        }
        Console.ReadKey();
    }
}

你这个问题网上很多类似的写法,你搜索参考参考,比如http://t.csdn.cn/0Whb2



```c#
using System;
using System.Threading;

namespace p2
{
    class Program
    {
        public void Demo()
        {
            int[] arr = new Int32[100];
            for (int i = 1; i < 101; i++)
            {
                if(i%7==0 && i%11!=0)
                {
                    arr[i - 1] = i;
                }
                else if(i%11==0&&i%7!=0)
                {
                    arr[i - 1] = i;
                }
            }

            int count = 0;

            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] != 0)
                {
                    count += 1;
                }
            }
            
            int[] a=new int[count];
            int j = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] != 0)
                {
                    a[j] = arr[i];
                    j += 1;
                }
            }
            Console.Write("数组a=[");
            for (int i = 0; i < a.Length; i++)
            {
                if (i != a.Length - 1)
                {
                    Console.Write(a[i]+",");
                }
                else
                {
                    Console.Write(a[i]);
                }

            }
            Console.WriteLine("]");
            int n = a.Length;
            Console.WriteLine("这些数的个数n="+n);
            Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            Program p=new Program();
            p.Demo();
        }
    }
}

```