snrg.net
当前位置:首页 >> 用C#编写一个控制台程序令用户输入一个数 求出该数... >>

用C#编写一个控制台程序令用户输入一个数 求出该数...

namespace ConsoleApplication3{ class Program { static void Main(string[] args) { int sum = 0; int v = int.Parse(Console.ReadLine()); do { int n = v % 10; sum += n; v /= 10; } while (v != 0); Console.WriteLine(sum); } } }

static void Main(string[] args) { Console.WriteLine("请输入n:"); String strInput = Console.ReadLine(); int n = Convert.ToInt32(strInput); //创建用于产生随机数的Random类 Random rd = new Random(); for (int k = 0; k < n; k++) { i...

见下面代码 using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { double [] myArray = new double[10]; Console.WriteLine("请输入十个数"); ...

class Program{ static void Main(stringp[] args) { Console.WriteLine("输入多个值,以空格分隔"); string value = Console.ReadLine(); string[] vals = value.Split(' '); Console.WriteLine("分开展示各值"); for (int i = 0; i < vals.Len...

c# 的程序的执行入口是 [STAThread] static void Main(string[] Args) 其中 (string[] Args) 就是你在控制台出入的参数,通过判断 Args 的数量就可以输出你要求的信息 示例 [STAThread] static void Main(string[] Args) { int iL = Args.Length...

static void Main(string[] args) { Console.WriteLine("输入一个正整数,并回车:"); int num = Convert.ToInt32(Console.ReadLine()); int re = 1; num.ToString() .Select(x => (int)char.GetNumericValue(x)) .ToList().ForEach( x => re *...

using System; using System.Console; class Program { public static void Main(string [] args) { int a = Integer.Parse(Console.Read()); int b = Integer.Parse(Console.Read()); Console.Write("{0}+{1}={2}\n",a,b,a+b); } } 大概这样,...

Main 函数里写: Console.Write("请输入一个字符串:"); string str = Console.ReadLine(); int count = 0;foreach (char c in str){ if (char.IsLetter(c)) { count ++; }}Console.WriteLine(string.Format("字符串{0}中字母的个数为:{1}", st...

int[] numbers = { 1, 2, 5, 4, 3 }; int i, j; int temp; for (i = 0; i < numbers.Length-1; i++) { for (j = 0; j < numbers.Length-1; j++) { if (numbers[j]>numbers[j+1]) { temp = numbers[j]; numbers[j] = numbers[j + 1]; numbers[j +...

Console.Write("\n输入年份,回车结束! \n"); string year = Console.ReadLine(); Console.Write("\n输入月份 ,回车结束! \n"); string mon = Console.ReadLine(); int y = Convert.ToInt32(year); int m = Convert.ToInt32(mon); int days =...

网站首页 | 网站地图
All rights reserved Powered by www.snrg.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com