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 程序图标添加数字
+(void)setAppIconNumber:(NSInteger)num{ if ([UIParam getIOSVersion]>8.0) { UIUserNotificationSett ...
- Linux下修改键盘映射
一篇关于修改键盘映射比较靠谱的文章,收藏一下! 原文地址:http://www.07net01.com/2016/04/1436249.html --------------------------- ...
- redis sets类型及操作
sets类型及操作set是集合,它是string类型的无序集合.通过hash table实现,添加.删除.查找的复杂度都是0(1).对集合我们可以实现取交际.差集并集.通过这些操作我们可以实现SNS中 ...
- HDU-2060-Snooker
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2060 题意: 给你场上剩下的球数m , 和 a ,b 两名队员目前得分,现在假设a将 所有的球m都打入 ...
- TForm类
显示给用户的窗体有两种:有模式和无模式的.具体使用哪一种窗体,取决于是否希望用户能够同时与这个窗体和其他窗体交互. 1.当打开一个模式窗体后,用户无法与应用程序的其他部分交互,知道用户关闭了这个窗体. ...
- jdk自带的动态代理
package com.stone.dp.proxy; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Met ...
- Flex移动皮肤开发(二)
范例文件 mobile-skinning-part2.zip 在这个讨论创建 Flex 移动 skin 的系列的 第 1 部分 中,我讨论了 Flex 团队在 Mobile 主题中所做的性能优化的原理 ...
- 从0到1学习node之简易的网络爬虫
本文地址: http://www.xiabingbao.com/node/2017/01/19/node-spider.html 我们这节的目标是学习完本节课程后,能进行网页简单的分析与抓取,对抓取到 ...
- TypeScript教程2
在TS中,我们允许开发人员使用面向对象技术. 1.类让我们看看一个简单的基于类的例子: class Greeter { greeting: string; constructor(message: s ...
- Vmware 的三种网络连接方式
VMWare提供了三种工作模式,host-only(主机模式).NAT(网络地址转换模式).bridged(桥接模式). 1.host-only(主机模式) 在某些特殊的网络调试环境中,如何要求将真实 ...