Re: [問題] C語言程式的問題~

看板TransCSI作者 ( )時間18年前 (2007/08/14 16:59), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
※ 引述《ssnn (也許..)》之銘言: : 請大家幫幫我~~謝謝 : 轩 Problem-1: 請輸入一整數值(1~9)據以印出底下之圖型(若輸入4則印出: : 1 : 12 : 123 : 1234 : 4321 : 321 : 21 : 1 #include <stdio.h> int main() { int input, i, j, k; printf("Please Input An Integer (1 ~ 9): "); scanf("%d", &input); for (i = 1; i <= input; i++) { for (j = 1; j <= i; j++) printf("%d", j); printf("\n"); } for (i = input; i >= 1; i--) { for (k = 0; k < input * 2 - i; k++) printf(" "); for (j = i; j >= 1; j--) printf("%d", j); printf("\n"); } return 0; } : 轩 Problem-4 : 請輸入二整數值(其一代表某月份之天數, 其二代表該月份第一天之星期數), 再據以印出該月份之月曆圖型(若輸入30與5則印出: : Sun Mon Tue Wed Thu Fri Sat : --- --- --- --- --- --- --- : 1 2 : 3 4 5 6 7 8 9 : 10 11 12 13 14 15 16 : 17 18 19 20 21 22 23 : 24 25 26 27 28 29 30 如何得知第一天是禮拜幾? 猜測題目是要求輸入"月份 & 第一天是星期幾"... 大概會是下面這個樣子 #include <stdio.h> void calendar(int month, int day, int t_day); int main() { int month, day; int t_day[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; printf("Month: "); scanf("%d", &month); /* 1 ~ 12 */ printf("Day: "); scanf("%d", &day); /* 1 ~ 7 */ if (month > 12 || month < 0 || day > 7 || day < 0) { printf("Error!\n"); } else { printf("---------------------------\n"); printf("Sun Mon Tue Wed Thu Fri Sat\n"); printf("---------------------------\n"); calendar(month, day, t_day[month -1]); printf("---------------------------\n"); } return 0; } void calendar(int month, int day, int t_day) { /* 先依據"第一天是星期幾"找出第一天的位置 再依序列出日期 應該不難 過程就略過囉 :p */ } 若有錯誤請指正,謝謝 :) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.57.132.241
文章代碼(AID): #16mMxi2u (TransCSI)
文章代碼(AID): #16mMxi2u (TransCSI)