作者chenbojyh (阿志)
看板ILSH-94313
標題[作業]一題計概題目
時間Fri Nov 25 01:45:20 2005
Write a program that determines the day number (1 to 366) in a year for a
date that is provided as input data. As an example, January 1, 1994, is day 1.
December 31, 1993, is day 365. December 31, 1996, is day 366, since 1996 is a
leap year. A year is a leap year if it is divisible by four, except that any
year divisible by 100 is a leap year only if it is divisible by 400. Your
program should accept the month, day, and year as integers. Include a function
leap that returns 1 if called with a leap year, 0 otherwise.
以下是我同學在老師給題目後下課馬上寫的:
----------
#include <stdio.h>
void main ()
{
int a,c,year,month,day;
printf("請輸入出生年份:");
scanf("%d",&year);
printf("請輸入出生月份:");
scanf("%d",&month);
printf("請輸入出生日期:");
scanf("%d",&day);
c=day;
if(!(year%4)&&(month>=3))
{c=c-1;}
else if((year%4)&&(month>=3))
{c=c-2;}
for(a=month-1;(a>=9)&&(a<=11);a--)
{
if (!(a%2))
{;c=c+31;}
else if(a%2)
{c=c+30;}
}
for( ;(a>=1)&&(a<=8);a--)
{
if (!(a%2))
{c+=30;}
else if(a%2)
{c+=31;}
}
printf("總日數為%d\n",c);
}
-------
他寫的跟我想的差不多(我還沒寫^^")
各位年輕有為的313同胞們
有辦法把這程式更簡單化嗎??
幫幫忙!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.220.101
推 YGJHSU:C語言...突然覺得好陌生... 11/25 02:01
推 chenbojyh:你們不是也用Problem Solving and Program Design in C 11/25 02:05
推 YGJHSU:我目前學的是 C++... 11/25 02:06
→ chenbojyh:在205頁第7題..... 11/25 02:06
→ chenbojyh:我也是呀!!!C++ 11/25 02:07
推 YGJHSU:?? 你上面的明明就是C... 11/25 02:13
→ iceboxi:是C沒錯= = 英文太濫理解題目中 囧 11/25 02:21
推 Laiyinhate:這本書還真多人用 @@ 這題我大一上的時候也寫過 11/25 02:41
推 chenbojyh:是喔!!C語言跟C++差在哪??? 11/25 02:43
→ chenbojyh:我們計概課用兩本書......這本是第二本 11/25 02:44
推 Laiyinhate:這本書錯誤還滿不少 我寫作業才拿出來看 11/25 02:46
推 chenbojyh:我們是用"Microsoft Visual C++ 6.0"來寫程式的... 11/25 02:47
→ Laiyinhate:C語言跟C++ 請看成2種不同的語言 11/25 02:48
→ iceboxi:某些寫法不同 你給的看print部份就知是C 11/25 03:14
推 chenbojyh:是喔!!金害....學業不精........ 11/25 03:26
→ sailorpow:這題高中不是教過?? 11/25 08:55
推 chaselsu:太簡單已至於無法解答~C++almost=C啊~只是功能爆強~我現꘠ 11/25 09:17
→ chaselsu:都麻混合用 11/25 09:18
→ chaselsu:"Microsoft Visual C++ 6.0編譯器太強~建議你去找個編譯븠 11/25 09:19
→ chaselsu:濫一點的~不過觀念比較不能弄清楚~但程式比較容易跑 11/25 09:19