zoukankan      html  css  js  c++  java
  • for循环实例2

    九九乘法表:

     //九九乘法表
                for (int x = 1; x < 10; x++) 
                {
                    for (int y = 1; y <=x;y++ )
                    {
                        Console.Write(y.ToString()+"*"+x.ToString()+"="+(x*y).ToString()+" "); 
                    }
                    Console.Write("
    "); 
                }
                Console.ReadLine();

    被七整除:

             int i = 0;
                Console.Write("请输入一个数");
                int n = Convert.ToInt32(Console.ReadLine());
                for (int num = 7; num < n; num++)
                {
                    if (num % 7 == 0)
                    {
                        Console.Write(num.ToString() + " ");
                        i++;
                    }
                }
                Console.Write("
    ");
                Console.Write("以上为"+n+"以内被7整除的数" + "
    " + "个数:" + i.ToString());
                Console.ReadLine();

    水仙花数:

                int a, b, c;
                int n = 0;
                for (int num = 100; num < 1000;num++ )
                {
                    a = Convert.ToInt16(num/100);
                    b = Convert.ToInt16(num/10-a*10);
                    c = Convert.ToInt16(num-(a*100+b*10));
                    if (n == a * a * a + b * b * b + c * c * c)
                    {
                        Console.Write(num.ToString() + " ");
                        n++;
                    }
                }
                Console.WriteLine();
                Console.Write("水仙花数的个数为" + n.ToString());
                Console.ReadLine();
  • 相关阅读:
    构建之法阅读笔记05
    构建之法阅读笔记04
    构建之法阅读笔记03
    第九周学习进度条
    个人冲刺
    第八周进度条
    Git疑难解决
    Git常用命令
    git配置SSH公钥
    Laravel框架中如何使用 Presenter 模式?
  • 原文地址:https://www.cnblogs.com/liuyudong0825/p/4704378.html
Copyright © 2011-2022 走看看