c#基础——for循环嵌套经典练习题(打★)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 作业题1
{
class Program
{
static void Main(string[] args)
{
//打行数
for (int i = ; i < ; i++)
//打列数
{
for (int j = ; j <= i; j++)
{
Console.Write("★");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
输出结果:

第二题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 作业题2
{
class Program
{
static void Main(string[] args)
{
//打行数
for (int i = ; i < ; i++)
//打列数
{
for (int j = ; j>i; j--)
{
Console.Write("★");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
输出结果:

第三题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 作业题3
{
class Program
{
static void Main(string[] args)
{
//打行数
for (int i = ; i < ; i++)
//打列数
{
for (int j = ; j > i+; j--)
{
Console.Write(" ");
} for (int t = ; t <= i; t++)
{
Console.Write("★");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
输出结果:

第四题
sing System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 作业题4
{
class Program
{
static void Main(string[] args)
{
//打行数
for (int i = ; i < ; i++)
//打列数
{
for (int j = ; j <= i-; j++)
{
Console.Write(" ");
} for (int t = ; t >i;t-- )
{
Console.Write("★");
}
Console.WriteLine();
}
Console.ReadLine(); } }
}
输出结果:

第五题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 作业题5
{
class Program
{
static void Main(string[] args)
{
//打行数
for (int i = ; i < ; i++)
//打列数
{
for (int j = ; j > i ; j--)
{
Console.Write(" ");
} for (int t = ; t <=i; t++)
{
Console.Write("★");
}
for (int p = ; p <= i-; p++)
{
Console.Write("★");
} Console.WriteLine();
}
Console.ReadLine();
}
}
}
输出结果:

第六题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 作业题6
{
class Program
{
static void Main(string[] args)
{
//打行数
for (int i = ; i <= ; i++)
{
for (int j =; j<i; j++)
{
Console.Write(" ");
} for (int t = ; t >i; t--)
{
Console.Write("★");
}
for (int m=; m>i-;m-- )
{
Console.Write("★");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
输出结果:

打菱形
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 作业总
{
class Program
{
static void Main(string[] args)
{
//打行数
for (int i = ; i < ; i++)
//打列数
{
for (int j = ; j > i; j--)
{
Console.Write(" ");
} for (int t = ; t <= i; t++)
{
Console.Write("★");
}
for (int p = ; p <= i - ; p++)
{
Console.Write("★");
} Console.WriteLine();
}
//打行数
for (int n = ; n <=; n++)
{
for (int j = ; j <n; j++)
{
Console.Write(" ");
} for (int t = ; t > n; t--)
{
Console.Write("★");
}
for (int m = ; m > n - ; m--)
{
Console.Write("★");
}
Console.WriteLine();
}
Console.ReadLine(); }
}
}
输出结果:

如果输入奇数,打印菱形,最多的一行★的数量等于你输入的这个数。
输入偶数,提示错误。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace boss级作业
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入一个奇数:");
int num = Convert.ToInt32(Console.ReadLine()); if (num % == )
{
//打行数
#region
for (int i = ; i <= (num + ) / ; i++)
//打列数
{
for (int j = ; j <= num - (num - ) / - i - ; j++)
{
Console.Write(" ");
} for (int r = ; r < * i - ; r++) { Console.Write("★"); } Console.WriteLine();
} #endregion # region
for(int i=;i<(num-)/;i++)
{
for(int j=;j<=i;j++)
{
Console.Write(" ");
}
for(int t=;t<(num-)-i*;t++)
{
Console.Write("★");
}
Console.WriteLine();
}
#endregion
} else
{
Console.WriteLine("您输入的数字是错误的!");
} Console.ReadLine();
}
}
}
输出结果:


c#基础——for循环嵌套经典练习题(打★)的更多相关文章
- JS循环+循环嵌套+经典例题+图形题
首先,了解一下循环嵌套的特点:外层循环转一次,内层循环转一圈. 在上一篇随笔中详细介绍了JS中的分支结构和循环结构,我们来简单的回顾一下For循环结构: 1.for循环有三个表达式,分别为: ①定义循 ...
- Java基础_循环嵌套_打印乘法口诀、菱形,各种图形,计算二元一次和三元一次方程组_7
循环嵌套 打印乘法口诀 for(int j=1;j<=9;j++){ for(int i=1;i<=j;i++){ System.out.print(i+"*"+j+& ...
- JAVA_SE基础——15.循环嵌套
嵌套循环是指在一个循环语句的循环体中再定义一个循环语句结构,while,do-while,for循环语句都可以进行嵌套,并且可以互相嵌套,下面来看下for循环中嵌套for循环的例子. 如下: publ ...
- 6、C#基础整理(for 语句经典习题--for循环嵌套、穷举)
1.for循环嵌套----最基础题目:求阶乘的和 ; int n = int.Parse(Console.ReadLine()); ; i < n; i++) { ;//定义变量sum1,每次循 ...
- 【视频+图文】Java基础经典练习题(一)输出2-100之间的素数,及素数个数
目录 第一题:判断2-100之间有多少个素数,并输出所有素数. 1.视频讲解: 2.思路分析: 代码讲解:以i=4为例 4.为大家准备了彩蛋: 能解决题目的代码并不是一次就可以写好的 我们需要根据我们 ...
- 2017-2-24 C#基础 for循环的嵌套
用几个练习题演示一下for循环的嵌套 1.打印以下图形 ★★★★★★★★★★★★★★★ namespace _2017_2_24_for循环的嵌套 { class Program { static v ...
- 【JS中循环嵌套常见的六大经典例题+六大图形题,你知道哪几个?】
首先,了解一下循环嵌套的特点:外层循环转一次,内层循环转一圈. 在上一篇随笔中详细介绍了JS中的分支结构和循环结构,我们来简单的回顾一下For循环结构: 1.for循环有三个表达式,分别为: ①定义循 ...
- java基础:进制详细介绍,进制快速转换,二维数组详解,循环嵌套应用,杨辉三角实现正倒直角正倒等腰三角,附练习案列
1.Debug模式 1.1 什么是Debug模式 是供程序员使用的程序调试工具,它可以用于查看程序的执行流程,也可以用于追踪程序执行过程来调试程序. 1.2 Debug介绍与操作流程 如何加断点 选择 ...
- 黑马程序员——JAVA基础之程序控制流结构之循环结构,循环嵌套
------- android培训.java培训.期待与您交流! ---------- 循环结构: 代表语句:while ,do while ,for while语句格式 : while(条件表达式) ...
随机推荐
- iOS 之 socket 与 http
http连接:短连接,发送一次请求,服务器响应后连接就断开. socket连接:长连接,连接后长期保持连接状态.
- HTML5定稿:手机App将三年内消失,互联网世界的第二次大战
HTML5与app以对立竞争的产品形态展现在大众视野.从去年开始又有一大批技术派或者创业者盯向html5领域,移动游戏的爆发和微信朋友圈等众多平台为HTML5导流,能不能颠覆,或许只是时间上的问题. ...
- quick-cocos2d-x添加到Pomelo的支持
https://github.com/luoxinliang/pomelo_quick_x/tree/master/pomelo_quick_x
- Canvas drawImage API
drawImage <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- lufylegend库 LButton
lufylegend库 LButton <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- Android离线缓存
android做到一定程度,需要考虑缓存的问题,不信可以掏出手机看看淘宝等一些app是否无网的情况下还可以浏览,不过大部分app并没有考虑到这些问题,解决Android的缓存有哪些方法呢 1.IO流读 ...
- 数据挖掘学习笔记--AdaBoost算法(一)
声明: 这篇笔记是自己对AdaBoost原理的一些理解,如果有错,还望指正,俯谢- 背景: AdaBoost算法,这个算法思路简单,但是论文真是各种晦涩啊-,以下是自己看了A Short Introd ...
- 使用python制作ArcGIS插件(5)其他技巧
使用python制作ArcGIS插件(5)其他技巧 by 李远祥 使用python做插件开发,除了了解ArcToolBox工具之外,还需要在了解ArcPy的相关函数和接口.只有掌握了这些,才可以顺利的 ...
- matlab中小技巧
关于matlab中可能遇到的小知识点 一.字符串的比较 不能使用“==”,需要使用函数strcmp() %matlab中字符串的比较 %字符串比较要用strcmp.相同则返回1,不相同则返回0. cl ...
- FZU 2167 大王叫我来巡山呐
Problem 2167 大王叫我来巡山呐 Accept: 931 Submit: 1405Time Limit: 1000 mSec Memory Limit : 32768 KB Pr ...