控制台程序 [英] console program

查看:116
本文介绍了控制台程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(找到可被5& 6整除的数字)编写一个程序,显示100到1000之间的所有数字,每行10个可被5和6整除的数字,但不能同时显示两个数字。数字间隔一个空格。

(find numbers divisible by 5&6)write a program that displays all the numbers fro 100 to 1000,ten per line that are divisible by 5 and 6, but not both. numbers are separated by exactly one space.

推荐答案

嗨朋友,

欢迎来到MSDN论坛。

Welcome to MSDN forum.

抱歉延误。你的实际问题是什么?你使用什么语言?

Sorry for the delay. What's your actual issue? And what language you use?

至于C#,一个简单的例子是:

As for C#, a simple sample is:

class Program
    {
        static void Main(string[] args)
        {
            CountAndDisplay();
        }

        public static void CountAndDisplay()
        {
            int[] MyList = new int[1000];
            int cnt=0;
            //find the numbers divisible by 5 or 6, but not both, and add them to an Int array
            for (int i = 100; i < 1001; i++)
            {
                if (((i % 5 == 0) && (i % 6 != 0)) || ((i % 5 != 0) && (i % 6 == 0)))
                {
                    MyList[cnt]=i;
                    cnt++;
                }
            }
            //output the date from the array, 10 per line
            for (int i = 0; i < cnt; i++)
            {
                Console.Write(MyList[i] + " ");
                if ((i + 1) % 10 == 0)
                {
                    Console.WriteLine("");
                }
            }
        }
    }

希望有所帮助。如果您使用C ++,python或者什么,请告诉我们,我们可以为您找到正确的论坛。

Hope it helps. And if you use C++ , python or what, let us know and we can find correct forum for you.

这篇关于控制台程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆