image.png
    String.IndexOf 方法

    1. int sum = 0;
    2. var Numbers = new List<int> { };
    3. int j;
    4. for (int i = 1; i <= 100; i++)
    5. {
    6. j = i.ToString().Length;
    7. if (((i % 7) == 0) || (i.ToString().IndexOf("7", 0, j) != -1))
    8. {
    9. sum = sum + i;
    10. Numbers.Add(i);
    11. }
    12. }
    13. Console.WriteLine("和为" + sum);
    14. foreach (var item in Numbers)
    15. {
    16. Console.WriteLine(item);
    17. }
    18. Console.ReadLine();

    image.png

    1. double sum = 100000;
    2. int fre = 0;
    3. while (sum > 5000)
    4. {
    5. if (sum > 50000)
    6. {
    7. sum = sum * 0.95;
    8. fre = fre + 1;
    9. }
    10. else if (sum <= 50000)
    11. {
    12. sum = sum - 5000;
    13. fre = fre + 1;
    14. }
    15. }
    16. Console.WriteLine($"最多经过{fre}次路口,余额为{sum.ToString("F1")}");
    17. Console.ReadLine();

    image.png

    1. var fibonacciNumbers = new List<int> { 1, 1 };
    2. for (int i = 2; i <= 36; i++)
    3. {
    4. int previous = fibonacciNumbers[i - 1];
    5. int preivous2 = fibonacciNumbers[i - 2];
    6. fibonacciNumbers.Add(preivous2 + previous);
    7. Console.WriteLine($"斐波拉契数列第{i+1}个数是{fibonacciNumbers[i]}");
    8. }

    image.png

    1. var list = new List<int> { };
    2. int count;
    3. for (int i = 100; i < 1000; i++)
    4. {
    5. int j = i % 10;
    6. int k = (i / 10) % 10;
    7. int m = i / 100;
    8. if (Math.Pow(j,3)+Math.Pow(k,3)+Math.Pow(m,3)==i)
    9. {
    10. list.Add(i);
    11. }
    12. }

    image.png

    1. int a=1;
    2. for (int i = 1; i < 7; i++)
    3. {
    4. a = Fun(a);
    5. Console.WriteLine(a.ToString());
    6. }
    7. Console.ReadKey();
    8. }
    9. static int Fun(int n)
    10. {
    11. return (n + 1) * 2;
    12. }