課程
/后端開發(fā)
/C#
/C#開發(fā)輕松入門
代碼
2017-09-20
源自:C#開發(fā)輕松入門 4-10
正在回答
?for (int x = 1; x <= 7; x++)//循環(huán)7行? ? ? ? ? ? {? ? ? ? ? ? ? ? for (int y = 1; y <= 7; y++)//循環(huán)7列? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? if (x == y || x + y == 8)//對(duì)角線打印O? ? ? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? ? ? Console.Write("O");? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? ? ? else? ? ? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? ? ? Console.Write(".");//其他位置打印.? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? Console.WriteLine();//換行? ? ? ? ? ? }
先不要慌著寫代碼,寫代碼之前先用偽代碼構(gòu)思算法和結(jié)構(gòu):例如:
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();
? ? ? ? ? ? }
? ? ? ? }
}
舉報(bào)
本門課程是C#語(yǔ)言的入門教程,將帶你輕松入門.NET開發(fā)
2 回答C#求解大神
3 回答求大神, c#的問題
2 回答求救大神如何使用C#輸入兩個(gè)正整數(shù),求他們的最小公倍數(shù)?
2 回答求大神教我
1 回答C#區(qū)分大小寫嗎?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-09-20
?for (int x = 1; x <= 7; x++)//循環(huán)7行
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int y = 1; y <= 7; y++)//循環(huán)7列
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (x == y || x + y == 8)//對(duì)角線打印O
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write("O");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write(".");//其他位置打印.
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine();//換行
? ? ? ? ? ? }
2018-04-22
先不要慌著寫代碼,寫代碼之前先用偽代碼構(gòu)思算法和結(jié)構(gòu):例如:
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();
? ? ? ? ? ? }
? ? ? ? }
? ? }
}