課程
/后端開發
/C#
/C#開發輕松入門
代碼
2017-09-20
源自:C#開發輕松入門 4-10
正在回答
?for (int x = 1; x <= 7; x++)//循環7行? ? ? ? ? ? {? ? ? ? ? ? ? ? for (int y = 1; y <= 7; y++)//循環7列? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? if (x == y || x + y == 8)//對角線打印O? ? ? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? ? ? Console.Write("O");? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? ? ? else? ? ? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? ? ? Console.Write(".");//其他位置打印.? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? Console.WriteLine();//換行? ? ? ? ? ? }
先不要慌著寫代碼,寫代碼之前先用偽代碼構思算法和結構:例如:
const n = 7
for(y =1~n){
? for(x =1~n){
? ? if(x==y || x==n-y+1){
? ? ?output(0);
? ? }
? ? output(*);
? }
? Change line;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test01
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? const int n = 7;
? ? ? ? ? ? for (int y = 1; y <= n; y++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int x = 1; x <= n; x++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (x == y || x == n - y + 1)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write("O");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? Console.Write(".");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine();
? ? ? ? ? ? }
? ? ? ? }
}
舉報
本門課程是C#語言的入門教程,將帶你輕松入門.NET開發
2 回答C#求解大神
3 回答求大神, c#的問題
2 回答求救大神如何使用C#輸入兩個正整數,求他們的最小公倍數?
1 回答C#區分大小寫嗎?
1 回答跪求解求解
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-09-20
?for (int x = 1; x <= 7; x++)//循環7行
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int y = 1; y <= 7; y++)//循環7列
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (x == y || x + y == 8)//對角線打印O
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write("O");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write(".");//其他位置打印.
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine();//換行
? ? ? ? ? ? }
2018-04-22
先不要慌著寫代碼,寫代碼之前先用偽代碼構思算法和結構:例如:
const n = 7
for(y =1~n){
? for(x =1~n){
? ? if(x==y || x==n-y+1){
? ? ?output(0);
? ? }
? ? output(*);
? }
? Change line;
}
2018-04-22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test01
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? const int n = 7;
? ? ? ? ? ? for (int y = 1; y <= n; y++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int x = 1; x <= n; x++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (x == y || x == n - y + 1)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write("O");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write(".");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine();
? ? ? ? ? ? }
? ? ? ? }
? ? }
}