循环语言(for)
循环语句:
给出初始条件,先判断是否满足循环条件,如果不满足条件则跳过for语句,如果满足则进入for语句循环,for语句内的代码执行完毕之后,将按照状态改变改变变量,然后判断是否符合循环条件,符合继续执行循环,知道变量i变得不符合条件为止或者遇见break跳出循环。
模版:
for (i=1(初始条件);i<100(循环条件);i++(状态改变))
{
执行
}
输入5的阶乘
Int sum=0;
Int jie=1;
For (i=1;i<=5;i++)
{
Jie*=i;
Sum+=jie
}
Console.WriteLine("5的阶乘是"+sum);
输入关卡数,得出分数
方法一:
/* Console.Write("请输入关卡数:");
int a = int.Parse(Console.ReadLine());
int n = 0;
{
if (a > 50&&a<1)
{
Console.WriteLine("输入有误!");
}
else
{
if (a <= 20)
{
for (int i = 1; i <= 20; i++)
n = n + i;
}
else if (a <= 30)
{
for (int i = 1; a <= 20; i++)
n = n + i;
for (int i = 1; a <= 30; i++)
n = n + 10;
}
else if (a <= 40)
{
for (int i = 1; a <= 20; i++)
n = n + i;
for (int i = 1; a <= 30; i++)
n = n + 10;
for (int i = 1; a <= 40; i++)
n = n + 20;
}
else if (a <= 49)
{
for (int i = 1; a <= 20; i++)
n = n + i;
for (int i = 1; a <= 30; i++)
n = n + 10;
for (int i = 1; a <= 40; i++)
n = n + 20;
for (int i = 1; a <= 49; i++)
n = n + 30;
}
else
{
for (int i = 1; a <= 20; i++)
n = n + i;
for (int i = 1; a <= 30; i++)
n = n + 10;
for (int i = 1; a <= 40; i++)
n = n + 20;
for (int i = 1; a <= 49; i++)
n = n + 30;
for (int i = 1; a == 50; i++)
n = n + 100;
}
Console.WriteLine("您输入的关卡积分是:" + n);
}
}
Console.ReadLine();
方法二:
Console.Write("请输入关卡数:");
int a = int.Parse(Console.ReadLine());
int n = 0;
if (a <= 50 && a >= 1)
{
for (int i = 1; i <= a; i++)
if (i <= 20)
{
n += i;
}
else if (i <= 30)
{
n = n + 10;
}
else if (i <= 40)
{
n = n + 20;
}
else if (a <= 49)
{
n = n + 30;
}
else if (a == 50)
{
n = n + 100;
}
}
else
{
Console.WriteLine("输入错误");
}
Console.WriteLine("您输入的关卡积分是:" + n);
Console.ReadLine();*/
篮球在20米的高空放下,每次弹起的高度是上一次的五分之四
Console.Write("请输入篮球弹起的次数:");
double a = double.Parse(Console.ReadLine());
double sum = 20;
for (int i = 1; i <= a; i++)
{
sum *=0.8;
}
Console.WriteLine("高度是:"+sum);
Console.ReadLine();*/
一张纸的厚度是0.07毫米,假设可以无限次的折叠,请问折叠多少次之后可以超过珠穆朗玛峰的高度8848米?
//Console.WriteLine("请问折纸多少次可以超过珠峰的高度?");
//int i = 0;
//double h = 0.07;
//for (;;)
//{
// ++i;
// h*=2;
// if (h > 8848000)
// {
// break;
// }
//}
//Console.WriteLine("折纸的次数是:{0},超过珠峰高度。",i);
//Console.ReadLine();
99乘法表
//for (int i=1; i <= 9; ++i)
//{
// for ( int j =1;j <=i; ++j)
// {
// int s = 1;
// s = j * i;
// Console.Write("{0}*{1}={2}\t",i,j,s);
// }
// Console.WriteLine();// Console.Write(\n);
//}
//Console.ReadLine();
//for (int i = 0; i < 5; ++i)
//{
// for (int j =0; j <5-i; ++j)
// {
// Console.Write("▲");
// }
// Console.WriteLine();
//}
//Console.ReadLine();
//for (int i = 0; i < 5; ++i)
//{
// for (int j = 0; j < i; ++j)
// {
// Console.Write(" ");
// }
// for (int j = 0; j < 5 - i; ++j)
// {
// Console.Write("▲");
// }
// Console.WriteLine();
//}
//Console.ReadLine();
输入一个数字,形成直角在左下角,高宽军事这个数字的三角形
//Console.Write("请输入一个正整数:");
//int a = int.Parse(Console.ReadLine());
//for (int i = 0; i < a; ++i)
//{
// for (int j = 0; j <= i; ++j)
// {
// Console.Write("▲");
// }
// Console.WriteLine();
//}
//Console.ReadLine();
//输入0到100以内的数字,找出其中与7相关的数字。
Console.Write("请输入一个整数:");
int a = int.Parse(Console.ReadLine());
for (int i =1; i <= a;i++ )
{
if(i%7==0||i%10==7||i/10==7)
Console.Write(" "+i);
}
Console.ReadLine();
循环语言(for)的更多相关文章
- 关于for循环------swift3.0
在程序开发当中,for循环使用的频率无疑是最高的.常用的swift循环是递增式遍历.当然各种循环,swift都能办到.但其大多采用关键字形式实现,大部分开发者更喜欢直接使用C式循环代码.在swift3 ...
- 嵌入式C语言优化小技巧
嵌入式C语言优化小技巧 1 概述 嵌入式系统是指完成一种或几种特定功能的计算机系统,具有自动化程度高,响应速度快等优点,目前已广泛应用于消费电子,工业控制等领域.嵌入式系统受其使用的硬件以及运行环境的 ...
- javascript递归、循环、迭代、遍历和枚举概念
javascript递归.循环.迭代.遍历和枚举概念 〓递归(recursion)在数学与计算机科学中,是指在函数的定义中使用函数自身的方法.递归一词还较常用于描述以自相似方法重复事物的过程.例如,当 ...
- Python入门一:基本数据类型
作为一个刚入门编程的大一狗,第一次写博客,希望能对自己学的知识进行巩固和提升,也希望记录自己成长的过程. 学习Python,一是因为暑假学的c++头疼,听说Python简单,那我就试试吧,二是因为Py ...
- 可爱的 Python : Python中函数式编程,第一部分
英文原文:Charming Python: Functional programming in Python, Part 1 摘要:虽然人们总把Python当作过程化的,面向对象的语言,但是他实际上包 ...
- outer的使用
outer就是一个标签,java语言中根本没有此关键字,因此outer也可以用其它的词来代替 java中的标签就是一个紧跟着英文冒号(:)的标识符.与其他语言不同的是,java中的标签只有放在循环语言 ...
- 浅析嵌入式C优化技巧
嵌入式C语言优化小技巧 1 概述 嵌入式系统是指完毕一种或几种特定功能的计算机系统,具有自己主动化程度高,响应速度快等长处,眼下已广泛应用于消费电子,工业控制等领域.嵌入式系统受其使用的硬件以及运行环 ...
- 人工机器:NDC-谷歌机器翻译破世界纪录,仅用Attention模型,无需CNN和RNN
终于找到ML日报的微信链接,抄之...................................... 请拜访原文链接:[谷歌机器翻译破世界纪录]仅用Attention模型,无需CNN和RNN. ...
- 使用Python绘制彩色螺旋矩阵
from turtle import* #导入turtle库 bgcolor("black") #设置画布颜色为黑色 speed(0) #设置画笔绘制速度 colors=[&quo ...
随机推荐
- hdu4778(状态压缩dp)
题意: 有G种颜色的宝石,共B袋.两个人轮流拿宝石,每次从B袋中拿一袋,把其中的所有宝石倒入一个公共容器,每袋宝石只能取一次. 当容器中有S个相同颜色的宝石时,将失去这S个宝石,当前操作者得到一个魔法 ...
- SAP EP 设置Portal别名安全模式
Securing the Portal Alias Cookie Context We recommend that you set the portal alias cookie to be del ...
- Ubuntu 16.04使用百度云的方案
Ubuntu没有很好的解决方案,都是一些投机取巧的方案: 1.不建议安装百度云客户端,尤其对于免费用户来说,会限制速度. 2.可以使用网页版进行文件上传. 3.下载可以通过Chrome点击下载后,复制 ...
- #!/usr/bin/env 脚本解释程序的作用
the Zimbu programming language http://www.zimbu.org/getting-started -------------------------------- ...
- windows 7中添加新硬件的两种方法(本地回环网卡)
最近在windows7上使用VMwareWorkstation7玩一些实验,遇到需要配置不同网络的问题. 因为在windows2003server上习惯使用要本地回环网卡了,那就想着在Windows7 ...
- Django打造大型企业官网(三)
四.前端首页 4.1.导航条实现 (1)templates/new/index.html <!DOCTYPE html> <html lang="en"> ...
- Photoshop制作的ico图标方法
photoshop是打不开ico的.只是能够通过安装插件实现. 插件点击这里能够下载. 用法,解压后的插件文件 粘贴到: (英文版路径) /program files/adobe/photoshop ...
- opencv对图像进行边缘及角点检測
opencv对图像进行边缘及角点检測 先看结果: 代码: // ConsoleApplication1_812.cpp : Defines the entry point for the consol ...
- 【bzoj4602】[Sdoi2016]齿轮
dfs,连边,边权为比值,赋值搜索,遇到矛盾时退出 #include<algorithm> #include<iostream> #include<cstdlib> ...
- HDU 5752Sqrt Bo
Sqrt Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...