急用的程式....誰可以幫我改...c#的 有程式碼在裡面.詳情請看內

Home Home
引用 | 編輯 穎欣
2005-04-03 22:35
樓主
推文 x0
= =...老師說要看起來像不同人寫的 ....但是我一點程式基礎都沒有....有人可以幫幫我嗎?
我會感激你的....拜託....還有誰可以交我畫流程圖......= =....程式真困難...

程式碼如下

using System;

namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要描述。
/// </summary>
class Class1 ..

訪客只能看到部份內容,免費 加入會員



獻花 x0
引用 | 編輯 MarkTzen
2005-04-03 23:37
1樓
  
一開始是讀入年份!因為讀進來的是string!所以再呼叫Convert.ToInt32轉成了數字型態(就是integer,在32bit的cpu裡,integer是32bit!所以轉也是稱為Int32)
再來call這支函式,就是再跑到下面去判斷
"除以4 等不等於零" 以及 "除以100要不等於零" 或者 "除以四百等於零" (這三個條件就是閏年的判斷)
***不過我的印象,應該是全部都&&(以及,也就是and)。
ok~呼叫完call,判斷了輸入的x,是不是閏年!1就是閏,0就不是~~

然後再把變數i,從1開始做迴圈!一直跑到2004年!把閏月的個數加在變數e!
中間就用變數n來接一直類加的i!再呼叫call!ref這個字眼,應該就是c++的&,reference的意思~
傳進去的變數,在裡面函式做的運算,會影響到出來後的變數值!

c/c++有兩種,一個就是pointer(指標)、另一個就是參考(reference)~~這個就要再多看看c#的語法了!

簡單介紹~~~有問題再來討論討論! 表情

獻花 x0
引用 | 編輯 唐老鴨
2005-04-04 00:43
2樓
  
我記個這個題目在範例區好像有阿....
還是這一區???
先去找找看囉 表情.....

我不會寫C#....
沒辦法幫你改囉....

獻花 x0
引用 | 編輯 panasonic732
2005-04-04 08:30
3樓
  
複製程式
int year,n,e=0,i=1,x;  //宣告變數

Console.WriteLine("輸入年份"); //螢幕印出 '輸入年份'
year = int.Parse(Console.ReadLine()); // Console.ReadLine 為讀進輸入的文字 資料形態.Parse 為轉該資料形態

x = call(year); //呼叫副程式

if(x==1)   //判段傳回值
Console.WriteLine("閏年"); 
else 
Console.WriteLine("平年");

while(i<=year) //這邊修改至所輸入的年份
{ 
i++; 
n = i; 
n=call(n); 
e+=n; 
} 
Console.WriteLine("共{0}個閏年",e); 
}


static void call(int y) //副程式
{ 

if(y%4==0&&y%100!=0||y%400==0) 
y=1;
else 
y=0;

return y;

} 

} 
} 



若有不能執行 請通知我
= =+

我是直接修改

流程圖可不可以用照片換阿...呵呵

獻花 x1
引用 | 編輯 hatacpk
2006-09-26 11:54
4樓
  
複製程式
using System; 

namespace Leap_year 
{ 
       /// <summary> 
       /// year的摘要描述。 
       /// </summary> 
       class year
       { 
              /// <summary> 
              /// 應用程式的主進入點。 
              /// </summary> 
              [STAThread] 
              static void Main(string[] args) 
              { 
                     // 
                     // TODO: 在此加入啟動應用程式的程式碼 
                     // 
                     int input; 
                     Console.WriteLine("請輸入年份"); 
                     input = Convert.ToInt32(Console.ReadLine()); 
                     leap_year(input); 
                     total_leap_year();
                     
              } 
              static void leap_year(int y) 
              { 
                     if(y % 4 == 0 && y % 100 !=0 || y % 400 == 0 ) 
                            Console.WriteLine("閏年");
                     else 
                            Console.WriteLine("平年");
              } 
              static void total_leap_year()
              {
                     int total_leap_year = 0;
                     for(int i = 1; i <= 2004 ; i++) 
                     { 
                            if(i % 4 == 0 && i % 100 !=0 || i % 400 == 0 )
                                   total_leap_year ++;
                     } 
                     Console.WriteLine("共" + total_leap_year + "個閏年"); 
              }
       } 
} 

這篇好久了啊!!!

獻花 x0