C 乙個小練習

2021-09-25 02:04:22 字數 788 閱讀 3338

using system.collections.generic;

using system;

namespace csharp入門經典exercises

public bool isalive()

return true;

}public int age

set}

public bool isewe

set}

}static void main(string args)

int flag = 0;//母羊生小羊標誌,flag為0生公羊,為1生母羊

int years=20;

//遍歷時不能對list進行新增刪除操作,不妨記錄要

for (;year<=years;year++)

//母羊如果年齡到了5歲就每年生一胎

for (int i = farmewe.count - 1; i > -1; i--)

}flag = flag == 0 ? 1 : 0;

console.writeline("第" + year + "年,公羊:" + sheep.numran + "只,母羊:" + sheep.numewe + "只");

}console.writeline(years+"年後,農場一共"+sheep.numran+"只公羊,"+sheep.numewe+"只母羊");}}

結果應該是沒錯的吧

Python教程 乙個小栗子和乙個小練習

python教程正在更新中 檢視python教程目錄 學了這麼多,我們來做幾個小練習。1.從命令列讀入出生年份是2001年,並且計算年齡例如那麼今年的年齡就是19歲 birth year input birth year age 2020 birth year print age 這是我們最樸素的思...

C 小練習,乙個整型數字的處理

define crt secure no warnings include 輸入乙個任意位數的int整數,並判斷該整數的位數,並輸出每一位數 每個數字中間用空格隔開,最後一位不需要空格 然後在倒序輸入每個數字 例子如下 輸入 12345 51 2 3 4 5 54321 int main print...

json學習的乙個小練習

做乙個登入註冊的練習 import json import time import hashlib username input 請輸入你的使用者名稱 檔名 f1 open username,r encoding utf 8 data1 f1.read data2 json.loads data1 ...