1. using System;
  2. class Program
  3. {
  4. static void Main()
  5. {
  6. Console.WriteLine("请输入两个整数:");
  7. int a = Convert.ToInt32(Console.ReadLine());//Console.ReadLine()默认读取字符串
  8. int b = Convert.ToInt32(Console.ReadLine());//Console.ToInt32()将读到的字符转换为带符号的32位整数
  9. int c = a + b;
  10. Console.WriteLine("两数之和是:" + c);
  11. Console.ReadLine();
  12. }
  13. }
  14.  
  15. using System;
  16. class Program
  17. {
  18. static void Main()
  19. {
  20. short a = 32767;
  21. a = a + (short)1;
  22. Console.WriteLine(a);
  23. }
  24. }
  25.  
  26. using System;
  27. class Program
  28. {
  29. static void Main()
  30. {
  31. int o = sizeof(byte);
  32. int a = sizeof(char);
  33. int b = sizeof(short);
  34. int c = sizeof(int);
  35. int d = sizeof(long);
  36. Console.WriteLine("在32位环境中字节型数所占的字节数为:" + o);
  37. Console.WriteLine("在32位环境中字节型数所占的字节数为:" + a);
  38. Console.WriteLine("在32位环境中字节型数所占的字节数为:" + b);
  39. Console.WriteLine("在32位环境中字节型数所占的字节数为:" + c);
  40. Console.WriteLine("在32位环境中字节型数所占的字节数为:" + d);
  41. }
  42. }
  43.  
  44. Convert.ToInt32("213145");//用Convert类将一个.NET基本数据类型转换成另一个.NET基本数据类型
  45.  
  46. int a=12345;
  47. string sn=a.ToString();//把a转换成字符串sn
  48. int b=int.Parse(sn);//把sn转换成整数b,结果b=a
  49.  
  50. //数据发生阶段示例
  51. using System;
  52. class Program
  53. {
  54. static void Main()
  55. {
  56. short i = 289;
  57. byte b;
  58. b = (byte)i;
  59. char c = (char)b;
  60. Console.WriteLine("{0}", c);
  61. }
  62. }
  63.  
  64. using System;
  65. class Program
  66. {
  67. static void Main()
  68. {
  69. int a = 12;
  70. a -= a * a;
  71. a += a;
  72. Console.WriteLine("a={0}", a);
  73. }
  74. }
  75.  
  76. using System;
  77. class Program
  78. {
  79. static void Main()
  80. {
  81. bool a = true;
  82. bool b = 5 < 3 && 7 > 4 || 8 > 5;
  83. int c = Convert.ToInt32(a && b);
  84. Console.WriteLine("c={0}", c);
  85. }
  86. }//1
  87.  
  88. using System;
  89. class Program{
  90. static void Main(){
  91. int a=10,b=20,c=30;
  92. bool m=(a<b&&b>c||a<b);
  93. Console.WriteLine(m);
  94. }
  95. }//true
  96.  
  97. using System;
  98. class Program
  99. {
  100. static void Main()
  101. {
  102. Console.Write("请输入第一个整数:");
  103. int a = Convert.ToInt32(Console.ReadLine());
  104. Console.Write("请输入第二个整数:");
  105. int b = Convert.ToInt32(Console.ReadLine());
  106. int max = a > b ? a : b;
  107. Console.WriteLine("两个整数的较大数是:{0}", max);
  108. }
  109. }
  110.  
  111. using System;
  112. class Program
  113. {
  114. static void Main()
  115. {
  116. bool b1 = false;
  117. Console.Write("请输入第一个数:");
  118. int m = Convert.ToInt32(Console.ReadLine());
  119. Console.Write("请输入第二个数:");
  120. int n = Convert.ToInt32(Console.ReadLine());
  121. b1 = m >= n ? true : false;
  122. Console.WriteLine("结果为:" + b1);
  123. }
  124. }
  125.  
  126. using System;
  127. class Program
  128. {
  129. static void Main()
  130. {
  131. Console.Write("请输入一个整数:");
  132. int x = Convert.ToInt32(Console.ReadLine());
  133. bool m = x > 0 && x <= 100 ? true : false;
  134. Console.WriteLine("{0}", m);
  135. }
  136. }
  137.  
  138. template <class T, class T1 = int, class T2 = int> class A;
  139.  
  140. template<class T, class T1 , class T2 >
  141. class A
  142. {
  143.  
  144. };
  145.  
  146. class B: public A<B, int>
  147. {
  148.  
  149. };
  150. int main(int argc, char* argv[])
  151. {
  152.  
  153. B b;
  154.  
  155. return 0;
  156. }
  157.  
  158. using System;
  159. class Program
  160. {
  161. static void Main()
  162. {
  163. int a = 240;
  164. int b = -16;
  165. int c = 44;
  166. Console.WriteLine("a={0}右移二位 a={1}", a, a >> 2);
  167. Console.WriteLine("b={0}右移二位 b={1}", b, b >> 2);
  168. Console.WriteLine("c={0}左移二位 c={1}", c, c << 2);
  169. }
  170. }
  171.  
  172. using System;
  173. class Program
  174. {
  175. static void Main()
  176. {
  177. int a = 7, b = 2;
  178. int c = a % b++;
  179. int d = -b;
  180. int e = b / (3 + a);
  181. int f = d + e - c;
  182. Console.WriteLine("f={0}", f);
  183. }
  184. }
  185.  
  186. //十进制,十六进制
  187. using System;
  188. class Program
  189. {
  190. static void Main()
  191. {
  192. int number = 1001;
  193. Console.WriteLine("十进制:{0:1}", number);
  194. Console.WriteLine("十六进制:{0:X}", number);
  195. Console.Write("{0,5}", 25);//三个空格
  196. Console.Write("{0:D5}", 25);//
  197. }
  198. }
  199.  
  200. //talkback.c--一个能为你提供一些信息的对话框
  201. #include<stdio.h>
  202.  
  203. #include<string.h>
  204.  
  205. #define DENSITY 62.4
  206.  
  207. int main()
  208. {
  209.  
  210. float weight, volume;
  211.  
  212. int size, letters, m;
  213.  
  214. char name[40];
  215.  
  216. printf("Hi! What's your first name?\n");
  217.  
  218. scanf("%s",name);
  219.  
  220. printf("%s, what'syour weight in pounds?\n",name);
  221.  
  222. scanf("%f",&weight);
  223.  
  224. size = sizeof name;
  225.  
  226. letters = strlen (name);
  227.  
  228. volume = weight / DENSITY;
  229.  
  230. printf("well, %s, your volume is %2.2f cubic feet.\n",name, volume);
  231.  
  232. printf("alsso, your first name has %d letters, \n",letters);
  233.  
  234. printf("and we have %d bytes to store it in.\n",size);
  235.  
  236. getchar();
  237.  
  238. return 0;
  239. }
  240.  
  241. using System;
  242. class Program
  243. {
  244. static void Main()
  245. {
  246. Console.Write("请输入一个年份:");
  247. string str = Console.ReadLine();
  248. int year = Int32.Parse(str);
  249. bool isleapyear = ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0));
  250. string yesno = isleapyear ? "是" : "不是";
  251. Console.WriteLine("{0}年{1}闰年", year, yesno);
  252. }
  253. }
  254.  
  255. using System;
  256. class Program
  257. {
  258. static void Main()
  259. {
  260. Console.Write("请输入一个年份:");
  261. string str = Console.ReadLine();
  262. int year = Int32.Parse(str);
  263. if ((year % 4 == 0) && (year % 100 != 0) || (year % 400) == 0)
  264. Console.WriteLine("{0}年时闰年", year);
  265. else
  266. {
  267. Console.WriteLine("{0}年不是闰年", year);
  268. }
  269. }
  270. }
  271.  
  272. using System;
  273. class Program
  274. {
  275. static void Main()
  276. {
  277. Console.Write("请输入一个整数分数:");
  278. int x = Convert.ToInt32(Console.ReadLine());
  279. if (x > 90)
  280. Console.WriteLine("优秀");
  281. else if (x > 80)
  282. Console.WriteLine("良好");
  283. else if (x > 70)
  284. Console.WriteLine("中等");
  285. else if (x > 60)
  286. Console.WriteLine("及格");
  287. else
  288. Console.WriteLine("不及格");
  289. }
  290. }
  291.  
  292. using System;
  293. class Program
  294. {
  295. static void Main()
  296. {
  297. Console.Write("请输入一个分数:");
  298. string x = Console.ReadLine();
  299. int m = Int32.Parse(x);
  300. int c = m / 10;
  301. switch(c){
  302. case 9:
  303. case 10:Console.WriteLine("优秀");break;
  304. case 8:Console.WriteLine("良好");break;
  305. case 7:Console.WriteLine("一般");break;
  306. case 6:Console.WriteLine("较差");break;
  307. default:Console.WriteLine("差");break;
  308. }
  309. }
  310. }
  311.  
  312. using System;
  313. class Program
  314. {
  315. static void Main()
  316. {
  317. int i = 1, sum = 0;
  318. while(i<=100)
  319. {
  320. sum += 1;
  321. i++;
  322. }
  323. Console.WriteLine("sum={0}", sum);
  324. }
  325. }
  326.  
  327. using System;
  328. class Program
  329. {
  330. static void Main()
  331. {
  332. int digit;
  333. Console.Write("输入一个整数");
  334. string x = Console.ReadLine();
  335. int num = int.Parse(x);
  336. Console.Write("反向显示结果");
  337. while(num!=0)
  338. {
  339. digit = num % 10;
  340. num = num /10;
  341. Console.Write(digit);
  342. }
  343. Console.WriteLine();
  344. }
  345. }

2014年3月5日C#训练的更多相关文章

  1. 马后炮之12306抢票工具(四)--抢票Demo,2014年1月9日终结版

    时隔一年多,终于朋友的忽悠下吧抢票Demo的最后一步完善了,与2014年1月9日成功生成车票. Demo仅经过自己测试,并未在高峰期进行测试,代码质量很差,因为赶工,套用去年模板并未使用设计模式. 代 ...

  2. 无插件的大模型浏览器Autodesk Viewer开发培训-武汉-2014年8月28日 9:00 – 12:00

    武汉附近的同学们有福了,这是全球第一次关于Autodesk viewer的教室培训. :) 你可能已经在各种场合听过或看过Autodesk最新推出的大模型浏览器,这是无需插件的浏览器模型,支持几十种数 ...

  3. 系列文章:老项目的#iPhone6与iPhone6Plus适配#(持续更新中,更新日期2014年10月12日 星期日 )

    本文永久地址为http://www.cnblogs.com/ChenYilong/p/4020399.html ,转载请注明出处. ********************************** ...

  4. 转:[置顶] 从头到尾彻底理解KMP(2014年8月22日版)

    [置顶] 从头到尾彻底理解KMP(2014年8月22日版)

  5. SQLSERVER2014 2014年4月1日发布

    SQLSERVER2014 2014年4月1日发布 原文地址: http://blogs.technet.com/b/microsoft_blog/archive/2014/03/18/sql-ser ...

  6. 千寻浏览器 1.0 Beta 1(524)(2014年5月27日)

    千寻浏览器--又一款新生浏览器今天进入各位浏览迷的视野.千寻浏览器基于IE内核,据传是由百度浏览器的上海团队操刀,在功能定位上,与目前的QQ浏览器有些相似. 千寻来自官方的解释:寻,追寻,探索,又是古 ...

  7. 2014年6月5日 深圳 IBM 安全解决方案会议通知

    2014年6月5日 深圳 IBM 安全解决方案会议通知 http://gdtesting.com/news.php?id=191 时间: 2014年6月5日 地点: 深圳大中华喜来登 议程: IBM安 ...

  8. 09.13日记(2014年9月13日00:18:26)英语,bootstrap,阮一峰,

    我们这里只推荐一本语法书:台湾的旋元佑老师写的<文法俱乐部>(简体版名为<语法俱乐部>).这本书因为出版社倒闭而绝版,淘宝可以买到影印的版本. (1)学英语:奶爸的英语教室 资 ...

  9. 【公告】CSDN个人空间将于2014年4月20日全新改版上线

    尊敬的用户:   你们好!           CSDN个人空间将在2014年4月20日全新改版上线!        CSDN个人空间是2008年8月推出的服务,致力于给广大用户提供在线技术分享和资料 ...

随机推荐

  1. 记一次 .NET 某招聘网后端服务 内存暴涨分析

    一:背景 1. 讲故事 前段时间有位朋友wx找到我,说他的程序存在内存阶段性暴涨,寻求如何解决,和朋友沟通下来,他的内存平时大概是5G 左右,在某些时点附近会暴涨到 10G+, 画个图大概就是这样. ...

  2. 【UE4 设计模式】适配器模式 Adapter Pattern

    概述 描述 将一个接口转换成客户希望的另一个接口,适配器模式使接口不兼容的那些类可以一起工作,其别名为包装器(Wrapper). 套路 Target(目标抽象类) 目标抽象类定义了客户所需要的接口,可 ...

  3. 【数据结构与算法Python版学习笔记】图——基本概念及相关术语

    概念 图Graph是比树更为一般的结构, 也是由节点和边构成 实际上树是一种具有特殊性质的图 图可以用来表示现实世界中很多有意思的事物,包括道路系统.城市之间的航班.互联网的连接,甚至是计算机专业的一 ...

  4. JVM:类加载与字节码技术-2

    JVM:类加载与字节码技术-2 说明:这是看了 bilibili 上 黑马程序员 的课程 JVM完整教程 后做的笔记 内容 这部分内容在上一篇笔记中: 类文件结构 字节码指令 编译期处理 类加载阶段 ...

  5. JDK里常见容器总结

    自己总结.   扩容 线程安全   是否支持null 的key 说明 hashmap 2*length 否   是 1.8以后增加红黑树.提高检索效率 hashtable   是   否 官方不建议使 ...

  6. [对对子队]会议记录4.15(Scrum Meeting 6)

    今天已完成的工作 何瑞 ​ 工作内容:制作了合成指南 ​ 相关issue:实现游戏内UI界面使用的组件 马嘉 ​ 工作内容:基本实现了箱子内物品列表 ​ 相关issue:实现游戏内UI界面使用的组件 ...

  7. Beta阶段第二次会议

    时间:2020.5.18 工作进展 姓名 工作 难度 完成度 ltx 1.在开小程序开发文档,学习相关知识 轻 85% xyq 1.完成活动场地申请可视化代码(耗时半天) 中 100% lm 1.设计 ...

  8. series和读取外部数据

    1.为什么学习pandas 我们并不是不愿意学习新的知识,只是在学习之前我们更想知道学习他们能够帮助我们解决什么问题.--伟哥 numpy虽然能够帮助我们处理数值,但是pandas除了处理数值之外(基 ...

  9. Spark面试题整理(三)

    1.为什么要进行序列化序列化? 可以减少数据的体积,减少存储空间,高效存储和传输数据,不好的是使用的时候要反序列化,非常消耗CPU. 2.Yarn中的container是由谁负责销毁的,在Hadoop ...

  10. (类)Program1.1

    1 class MyClass: 2 3 i = 12345 4 5 def __init__(self): 6 self.data = "WOOWOWOWO" 7 8 def f ...