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

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

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("请输入十个数"); ...

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 *...

static void Main(string[] args) { int n = 0; n = Convert.ToInt32(Console.ReadLine()); int result = sum(n); Console.WriteLine(result.ToString()); Console.ReadLine(); } private static int sum(int n) { int j = 1; //结果 int result...

Random ran = new Random(); int a = ran.Next();//随便生成个 int b = ran.Next(8);//小于8的非负随机数 int c = ran.Next(100,200);//100至200之间的数

public int[] GetFactors(int n){ int Count = 0; int[] temp = new int[n]; for(int i = 1; i < n; i++){ if (n % i == 0) { temp [Count] = i; Count++; } } int[] OutFactors = new int[Count]; for (int i = 0; i < OutFactors.Length; i++)...

using System; class P{ static void Main(string[] args) {int n=0;int temp;int sum;while(true){Console.Write("n = ");n=int.Parse(Console.ReadLine());if(n==-1) return;sum=3*n+1;temp=n;while(n>2){n--;temp*=n;}sum+=temp;Console.Wri...

我也真是无聊, 帮别人做作业, 算了, 当个好人. 送你了.

static void Main(string[] args) { string str = Console.ReadLine(); int n = Convert.ToInt32(str); double result = sum(n); Console.WriteLine("阶乘的和"+result); Console.ReadKey(); }private static double sum(int n) { if (n

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