- 525
- 0
- 约2.87万字
- 约 24页
- 2017-06-25 发布于河南
- 举报
29个经典C#小例子
1
// (2)编写程序,输出100以内个位数为6且能被3整除的所有的数。
using System;
using System.Collections.Generic;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i 100; i++)
if ((i % 10 == 6) (i % 3 == 0))
Console.WriteLine(i);
}
}
}
7
// (3)编写一个简单的计算器程序,能够根据用户从键盘输入的运算指令和整数,进行简单的加减乘除
运算。
using System;
using System.Collections.Generic;
using System.Text;
namespace exercise3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(请输入两个运算数字:);
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(请输入运算符号:);
char s = Convert .ToChar (Console .ReadLine());
switch (s)
{
case +: Console.WriteLine(a + + + b + ={0}, a + b); break ;
case -: Console.WriteLine(a + - + b + ={0}, a - b); break ;
case *: Console.WriteLine(a + * + b + ={0}, a * b); break ;
case /: Console.WriteLine(a + / + b + ={0}, (Single )a / b); break ;
default: Console.WriteLine(输入的运算符有误!); break ;
}
}
}
}
8// (4)合数就是非素数,即除了1和它本身之外还有其他约数的正整数。
//编写一个程序求出指定数据范围(假设10~100)内的所有合数。
using System;
using System.Collections.Generic;
using System.Text;
namespace exercise4
{
class Program
{
static void Main(string[] args)
{
for(int i =10;i=100;i++)
for(int j =2;ji/2;j++)
if (i % j == 0)
{
Console.Write(i);
Console.Write( );
break ;
}
}
}
}
9
// (1)定义两个方法,分别求两个正整数的最大公约数和最小公倍数。
//其中,最大公约数的计算采用辗转相除法;最小公倍数的计算采用先计算最大公约数,
//然后再用两个数的积去除最大公约数来求得。
//在Main方
您可能关注的文档
- 菊次郎夏天.ppt
- 获得教养途径(公开课).ppt
- 营业税暂行条例与其实施细则政策解读.ppt
- 营养师 营养师重点复习.ppt
- 营造良好课堂教学气氛_71731.doc
- 菲霖公馆项目蓄客认筹策略与活动方案.ppt
- 营业员招聘面试技巧.ppt
- 营运计划与考核工作汇报模板.ppt
- 营造良好课堂教学气氛.doc
- 营养平衡食谱设计和编制_中国居民平衡膳食宝塔法.ppt
- 2026年人力资源行业服务升级员工体验优化.docx
- 2026年红枣加工行业市场前景预测与产品创新现状.docx
- 2026年无人机电力巡检行业五年发展趋势报告.docx
- 2026年中国不锈钢材料配件市场调查研究报告.docx
- 2026年智能电梯节能改造方案报告.docx
- 2026年航空货运高端运输市场趋势十年分析报告.docx
- 2025-2026学年高中信息技术(信息科技)必修2 信息系统与社会沪科版(2019)教学设计合集.docx
- 2026年颜料行业国际市场竞争策略及技术创新应用前景报告.docx
- 2026年中国涤棉纱市场调查研究报告.docx
- 2026年量化资管行业十年发展趋势报告.docx
原创力文档

文档评论(0)