c# 作业1
2016-03-29 20:51
537 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication8 { class Program { static void Main(string[] args) { ConsoleKeyInfo c; do { System.Console.WriteLine("请输入一个大于100的整数"); int a = 0; string number = Console.ReadLine(); int.TryParse(number, out a); //Console.WriteLine("{0}", a); int[] b = new int[1000]; int cnt = 0; while (a != 0) { b[cnt++] = a % 10; a /= 10; } Console.WriteLine("该整数一共有{0}位", cnt); int sum = 0; Console.Write("实现思路1: 每一位的值为"); for (int i = cnt - 1; i >= 0; --i) { Console.Write("{0}、", b[i]); sum += b[i]; } Console.Write(", 这些位之和为{0}", sum); Console.WriteLine(""); Console.Write("实现思路2: 每一位的值为"); sum = 0; for (int i = 0; i < number.Length; ++i) { Console.Write("{0}、", number[i]); sum += number[i] - '0'; } Console.Write(", 这些位之和为{0}", sum); Console.WriteLine(""); Console.WriteLine("按回车键退出,其他键继续!"); c = Console.ReadKey(); } while (c.Key != ConsoleKey.Enter); } } }
相关文章推荐
- 新旧图幅号转换公式及示例代码(C#)
- 第二章《深入C#数据类型》项目经理评分
- c#屏幕录制
- c#中接口实现类的动态调用实现
- C#使用黑体字
- C#扫盲之:前台线程后台线程
- C#中的多线程 - 基础知识
- C#实现smartQQ 扫码登录分析自动收发消息
- c#命名规则和代码规则
- C# C sharp保存读取文件 定时器 数组转16进制字符串 源码
- 深入C#数据类型
- c#LINQ学习
- C# 中 KeyPress 、KeyDown 和KeyPress的详细区别[转]
- C# 发送Post请求(带参数)
- C# 委托-lambda表达式
- C# TreeView的帮助类
- C#添加DLL文件
- C#静态构造函数
- C#的Session偶尔查询不到的问题
- C# 4.5以下超时