有一函数:当x<0时,y=-1;当x=0时,y=0;当x>0时,y=1。

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个数:");

int sum = 0, i;
for (i = 1; i <= 100; i++)
{ sum += i; }
Console.WriteLine(sum);
Console.ReadKey();

}
}
}

有一函数:                          

                            x     (x<1);            

                  Y= 2x-1     (1<=x<10);                     

                      3x-11    (x>=10); 

写一程序,输入X的值,输出Y的值。

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.Write("输入x的值:");
int y = 0;
int x = Convert.ToInt32(Console.ReadLine());
if (x < 1)
{ y = x; }
else if (x < 10)
{ y = 2 * x - 1; }
else
{ y = 3 * x - 11; }
Console.WriteLine("y值为:{0}", y);
Console.ReadKey();

}
}
}

编程求1+2+3+…+100的值,并输出结果

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int sum = 0, i;
for (i = 1; i <= 100; i++)
{ sum += i; }
Console.WriteLine(sum);
Console.ReadKey();

}
}
}

判断m是否为素数

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.Write("输入m的值:");
int m = Convert.ToInt32(Console.ReadLine());
bool isSuShu=false;
for (int i = 2; i <= Math.Sqrt(m); i++)
{
if (m % i == 0)
{
isSuShu =false ;
break;
}
else
{ isSuShu = true; }
}

if (isSuShu)
{ Console.WriteLine("是素数"); }
else
{ Console.WriteLine("不是素数"); }
Console.ReadKey();

}
}
}

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.Write("输入x的值:");
int m = Convert.ToInt32(Console.ReadLine());
for (int i = 2; i <= Math.Sqrt(m); i++)
{
//错误的方法,哪位高手能提供这种方法的实现!
if (m % i != 0)
{
Console.WriteLine("是素数");

}
else
{
Console.WriteLine("不是素数");

}
}
Console.ReadKey();

}
}
}

输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int letters = 0, space = 0, digit = 0, others = 0;
string strs = Console.ReadLine();
char[] chars = strs.ToCharArray();
foreach (char c in chars)
{
if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
letters++;
else if (c == ' ')
space++;
else if (c >= '0' && c <= '9')
digit++;
else
others++;
}
Console.WriteLine("字母有{0}个\n空格有{1}个\n数字有{2}个\n其他{3}个

", letters,space,digit,others);
Console.ReadKey();
}
}
}

求S=a+aa+aaa+...+aaa...aa之值,其中a是一个数字,n表示a的位数

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int sum=0, a=0, an=0,count=0,n;
Console.Write("请输入一个数字:");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入位数:");
n = Convert.ToInt32(Console.ReadLine());
while(count<n)
{
an += a;
a = a * 10;
sum += an;
++count;
}
Console.WriteLine(sum);
Console.ReadKey();
}
}
}

求1+2!+3!+4!+…+20!

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int n, s = 0, t = 1;
for (n = 1; n <= 20; n++)
{
t = t * n;
s = s + t;
}
Console.WriteLine("1!+2!+…+20!={0}", s);
Console.ReadKey();
}
}
}

输出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个“水仙花数”,因为153=1的三次方+5的三次方+3的三次方。

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("water flower number is:");
for (n = 100; n < 1000; n++)
{
i = n / 100;
j = n / 10 % 10;
k = n % 10;
if (i * 100 + j * 10 + k == i * i * i + j * j * j + k * k * k)
Console.WriteLine(n);
}
Console.ReadKey();
}
}
}

有一分数序列:2/1,3/2,5/3,8/5,….,21/13,……前二十项之和。

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
float i, t, n = 20;
float a = 2, b = 1, s = 0;
for (i = 1; i <= n; i++)
{
s = s + a / b;
t = a;
a = a + b;
b = t;
}
Console.WriteLine("sum={0}", s);
Console.ReadKey();
}
}
}

转载于:https://www.cnblogs.com/tuobazjs/archive/2011/06/18/2084446.html

c# 经典521例(2)相关推荐

  1. 求一批整数中出现最多的个位数字_C语言经典100例007-求低n-1位的数

    系列文章<C语言经典100例>持续创作中,欢迎大家的关注和支持. 喜欢的同学记得点赞.转发.收藏哦- 后续C语言经典100例将会以pdf和代码的形式发放到公众号 欢迎关注:计算广告生态 即 ...

  2. 北京邮电大学c语言按要求输出_C语言经典100例004-统计各个年龄阶段的人数

    系列文章<C语言经典100例>持续创作中,欢迎大家的关注和支持. 喜欢的同学记得点赞.转发.收藏哦- 后续C语言经典100例将会以pdf和代码的形式发放到公众号 欢迎关注:计算广告生态 即 ...

  3. python 经典100例 (61-80)

    python 经典100例(61-80) ''' [程序61] 题目:打印出杨辉三角形(要求打印出10行如下图) 1.程序分析: ''' if __name__ == '__main__': a = ...

  4. python经典100例(41-60)

    python 经典100例(41-60) ''' [程序41] 题目:学习static定义静态变量的用法 1.程序分析: 2.程序源代码: ''' # python没有这个功能了,只能这样了:) de ...

  5. python入门经典27版_【python】编程语言入门经典100例--27

    [python]编程语言入门经典100例--27 发布时间:2020-02-27 20:35:50 来源:51CTO 阅读:520 作者:snc_snc 1 #题目:利用递归函数调用方式,将所输入的5 ...

  6. require mysql.php_require和include经典一例抛析_php

    在php中,include和require的作用比较容易混淆.下面我以一个经典例子来深刻说明它们的区别. 当我们经常访问一个数据库时,可以把连库语句写成一个文件 con_db.php3 $dbh =  ...

  7. python入门经典100例-Python3经典100例(含习题答案) DOC 清晰版

    给大家带来的一篇关于Python3入门相关的电子文档资源,介绍了关于Python3.python习题方面的内容,本书是由python学习社区出版,格式为DOC,资源大小46.6 KB,Mrs.莫建辉编 ...

  8. 《JavaScript网页特效经典300例》

    <JavaScript网页特效经典300例> 基本信息 作者: 杨磊    张志美 丛书名: 百炼成钢系列丛书 出版社:电子工业出版社 ISBN:9787121220524 上架时间:20 ...

  9. python经典100例下载_Python3经典100例(含习题答案) DOC 清晰版

    给大家带来的一篇关于Python3入门相关的电子文档资源,介绍了关于Python3.python习题方面的内容,本书是由python学习社区出版,格式为DOC,资源大小46.6 KB,Mrs.莫建辉编 ...

最新文章

  1. pandas 季度_当缺少季度时,如何确定pandas数据帧的季度行值的差异
  2. C++ 中在函数的前面加上static的作用
  3. for循环中pairs与ipairs的区别与联系
  4. C#秘密武器之反射——基础篇
  5. 剑指Offer - 面试题60. n个骰子的点数(动态规划)
  6. 解决npm install安装慢的问题
  7. Jquery常用开发插件收集
  8. 自适应t分布与动态边界策略改进的算术优化算法
  9. 加速器在模拟器中的尝试
  10. 프로그래머로 살아남는 법
  11. 我与谷歌共成长--谷歌常用的技巧#我和 Google 谷歌共成长
  12. html实现文字滚动
  13. 在html中怎么格式化输出json字符串
  14. java 汉字转换全拼、首字母拼音
  15. 数据分析展示B站UP主假吃强(Cram阿强)的面目-视频与简介篇
  16. 浅谈单片机低功耗处理
  17. 基于网格搜索优化支持向量机的负荷预测方法
  18. 从《波斯语课》电影,思考当下紧张的形势,该如何准备面试?
  19. LambdaMART介绍
  20. #HHD32F107# watch dog

热门文章

  1. 开机f8修复电脑步骤_电脑维修实战,修复电脑开机的各种报错提示,看了不后悔...
  2. python 调用event handler_python-如何获取调用事件的窗口小部件的ID(...
  3. python ggplot画等值线图,是否可以在Python ggplot上绘制多折线图?
  4. mysql 表分区 django_MySQL partition分区I
  5. mysql v8 漏洞_mysql'密码安全 - osc_v8gts6gd的个人空间 - OSCHINA - 中文开源技术交流社区...
  6. python去除中间空格只留一个_汇总初学Python的21个操作难点,看完别再去踩坑了...
  7. win7发现不了无线网络_win10系统间设置共享文件夹后“网络”选项下仍然无任何文件(即发现不了共享电脑)...
  8. sqlplus可以连接plsql连接不上_为什么有的iPhone/iPad连接不上电脑?
  9. HPAIC人类蛋白质图谱分类挑战赛金牌经验分享
  10. [oracle]常用SQL汇总