c语言:使用while语句求出1到100以内所有能被3整除或能被7整除的自然数

如题所述

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication7

{

    class Program

    {

        static void Main(string[] args)

        {

            int x = 1;

            while (x++ <= 100)

            {

                if (x % 3 == 0)

                {

                    Console.WriteLine(x);

                }

            }

            Console.ReadLine();

                

        }

    }

}



扩展资料:

JavaScript中while循环的语法如下:

while (<条件>) {需执行的代码 };

do {需执行的代码 } while (<条件>);

注意:do...while 循环是 while 循环的变种。该循环程序在初次运行时会首先执行一遍其中的代码,然后当指定的条件为 true 时,它会继续这个循环。

所以可以这么说,do...while 循环为执行至少一遍其中的代码,即使条件为 false,因为其中的代码执行后才会进行条件验证。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-03-31
int i = 1;
while(i<1O1)
{

if(i%3==O ll i%7==O)
printf("%d ",i);
i++;

}本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网