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(条件表达式) ...
随机推荐
- 1.4. 为现有的应用程序添加 Core Data 支持(Core Data 应用程序实践指南)
项目创建时会有 “Use Core Data" ,但是,有时没有勾选这个选项,那么就要手动链接Core Data Framework. 选中 Grocery Dude Target Gene ...
- 在asp.net中使用ajax记录
一.问题描述 ajax在mvc中使用频繁,比如cms中的评论功能,但由于涉及到前后端开发,日久容易忘,在此做下记录. 二.内容 控制器中代码示例: /// <summary> /// 在文 ...
- php实现断点下载
HTTP断点续传原理 Http头 Range.Content-Range() HTTP头中一般断点下载时才用到Range和Content-Range实体头, Range用户请求头中,指定第一个字节的位 ...
- js原生设计模式——13桥接模式(相同业务逻辑抽象化处理的职责链模式)
桥接模式之多元化类之间的实例化调用实例 <!DOCTYPE html><html lang="en"><head> <meta ch ...
- js验证IP及子网掩码的合法性
function checkIP(ip) { obj=ip; var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0 ...
- NamingException with message: Name [spring.liveBeansView.mbeanDomain]
spring mvc启动出现 NamingException with message: Name [spring.liveBeansView.mbeanDomain],解决方式: 在web.xml中 ...
- ubuntu开机自动关闭独显,使用集成显卡
我的本子是联想y470p-ise,因为是有双显卡,而ubuntu在开机后,双显卡默认是同时工作,会产生巨大的发热,导致很不爽.而且在ubuntu下基本我也不用独显,所以有开机关闭独显的需求. ubun ...
- json-lib之复杂数据类型的转换
在json字符串转java bean时,一般的对象,可以直接转,如:一个学生类,属性有姓名.年龄等 public class Student{ private String sname; privat ...
- iOS-直播开发(开发从底层做起)
一直在忙, 也没写过几次播客! 但一直热衷于直播开发技术, 公司又不是直播方向的, 所以就年前忙里偷袭研究了一下直播开发, 然后翻阅了很多大神的技术博客等, 写了一个简单的Demo, 又根据网上大神们 ...
- 华为oj---合并数组
题目标题: 将两个整型数组按照升序合并,并且过滤掉重复数组元素 详细描述: 接口说明 原型: voidCombineBySort(int* pArray1,intiArray1Num,int* pAr ...