中國大學MOOC(C語言程式設計精髓)作業

2021-09-05 01:31:59 字數 4866 閱讀 7837

用結構體定義時鐘型別,程式設計從鍵盤任意輸入兩個時間(例如4時55分和1時25分),計算並輸出這兩個時間之間的間隔。要求不輸出時間差的負號。結構體型別定義如下:

typedef struct clock

int hour;

int minute;

int second;

} clock;

函式原型: clock calculatetime(clock t1, clock t2);

函式功能:計算並返回兩個時間t1和t2之間的差

程式執行結果示例1:

input time one:(hour,minute):4,55↙

input time two: (hour,minute):1,25↙

3hour,30minute

程式執行結果示例2:

input time one:(hour,minute):1,33↙

input time two: (hour,minute):5,21↙

3hour,48minute

"input time two: (hour,minute):"
輸入格式: 「%d,%d」

輸出格式:"%dhour,%dminute\n"

為避免出現格式錯誤,請直接拷貝貼上題目中給的格式字串和提示資訊到你的程式中。

時間限制:500ms記憶體限制:32000kb

c語言實現:

#include #include typedef struct clock

clock;

clock calculatetime(clock t1, clock t2);

int main()

clock calculatetime(clock t1, clock t2)

else if(t1.hour<0 || t1.minute<0)

else ;

return t1;

}

2、獎學金發放(4分)

題目內容:

某校的慣例是在每學期的期末考試之後發放獎學金。發放的獎學金共有五種,每項獎學金獲取的條件分別如下:

五四獎學金:期末平均成績高於85分(>85),並且班級評議成績高於80分(>80)的學生每人均可獲得4000元;

成績優秀獎:期末平均成績高於90分(>90)的學生每人均可獲得2000元;

西部獎學金:期末平均成績高於85分(>85)的西部省份學生每人均可獲得1000元;

班級貢獻獎:班級評議成績高於80分(>80)的學生幹部每人均可獲得850元;

只要符合上述條件就可獲得相應的獎項,每項獎學金的獲獎人數沒有限制,每名學生也可以同時獲得多項獎學金。例如姚明的期末平均成績是87分,班級評議成績82分,同時他還是一位學生幹部,那麼他可以同時獲得五四獎學金和班級貢獻獎,獎金總數是4850元。

現在給出若干學生的相關資料(假設總有同學能滿足獲得獎學金的條件),請程式設計計算哪些同學獲得的獎金總數最高。

結構體型別定義如下:

typedef struct winners

char name[20];

int finalscore;

int classscore;

char work;

char west;

int *****;

int scholarship;

} win;

函式原型:void addup(win stu, int n);

函式原型:int findmax(win student, int n);

程式執行結果示例:

input n:4↙

input name:yaoming↙

input final score:87↙

input class score:82↙

class cadre or not?(y/n):y↙

students from the west or not?(y/n):n↙

input the number of published *****s:0↙

name:yaoming,scholarship:4850

input name:chenruiyi↙

input final score:88↙

input class score:78↙

class cadre or not?(y/n):n↙

students from the west or not?(y/n):y↙

input the number of published *****s:1↙

name:chenruiyi,scholarship:9000

input name:lixin↙

input final score:92↙

input class score:88↙

class cadre or not?(y/n):n↙

students from the west or not?(y/n):n↙

input the number of published *****s:0↙

name:lixin,scholarship:6000

input name:zhangqin↙

input final score:83↙

input class score:87↙

class cadre or not?(y/n):y↙

students from the west or not?(y/n):n↙

input the number of published *****s:1↙

name:zhangqin,scholarship:8850

chenruiyi get the highest scholarship 9000

輸入格式:

輸入學生人數:"%d"

輸入學生姓名:"%s"

輸入學生成績:"%d"

輸入是否為學生幹部:" %c" (注意:%c前面有乙個空格)

輸入是否為西部學生:" %c" (注意:%c前面有乙個空格)

輸出格式:

輸出學生獲得的獎學金:  "name:%s,scholarship:%d\n"

輸出獲得獎學金總數最高的學生:"%s get the highest scholarship %d\n"

為避免出現格式錯誤,請直接拷貝貼上題目中給的格式字串和提示資訊到你的程式中。

時間限制:500ms記憶體限制:32000kb

c語言實現:

#include  #define n 10

typedef struct winners

win;

void addup(win stu, int n);

int findmax(win student, int n);

int main()

int findmax(win student, int n)

; int n, i, ret;

int a[3]=;

printf("input the number of electorates:");

scanf("%d", &n);

for(i=0;i4、星期判斷(4分)

題目內容:請輸入星期幾的第乙個字母(不區分大小寫)來判斷一下是星期幾,如果第乙個字母一樣,則繼續判斷第二個字母(小寫),否則輸出「data error」。

程式執行結果示例1:

please input the first letter of someday:

s↙please input second letter:

u↙sunday

程式執行結果示例2:

please input the first letter of someday:

f↙friday

程式執行結果示例2:

please input the first letter of someday:

h↙data error

第乙個字母的輸入提示資訊:「please input the first letter of someday:\n」

第二個字母的輸入提示資訊:「please input second letter:\n」

使用者輸入錯誤提示資訊:「data error\n」

輸入格式: " %c" (注意:%c前面有乙個空格)

輸出格式:

星期一:「monday\n」

星期二:「tuesday\n」

星期三:「wednesday\n」

星期四:「thursday\n」

星期五:「friday\n」

星期六:「saturday\n」

星期日:「sunday\n」

為避免出現格式錯誤,請直接拷貝貼上題目中給的格式字串和提示資訊到你的程式中。

時間限制:500ms記憶體限制:32000kb

c語言實現:

#include #include#define n 10

int main()

; char ch1,ch2;

int i,x=-1,flog=0;

printf("please input the first letter of someday:\n");

scanf(" %c",&ch1);

for(i=1;i<=7;i++)

if(ch2==a[i][1])

}} switch(x)

case 2:

case 3:

case 4:

case 5:

case 6:

case 7:

case -1:

} return 0;

}

中國大學MOOC(C語言程式設計精髓)作業

編寫程式利用遞迴法實現如下所示n層巢狀平方根的計算 遞迴函式原型 double y double x,int n 程式執行結果示例1 please input x and n 16,1 result 4.00 程式執行結果示例2 please input x and n 16,2 result 4....

中國大學MOOC C語言筆記03

5.1迴圈控制 判斷素數 如下 include int main printf f d f n n,sum return 0 求和 f n 1 1 2 1 3 1 4 1 5 如下 include int main printf f d f n n,sum return 0 求最大公約數 兩種演算法...

中國大學改名

sb篇 北京語言學院 北京語言文化大學 北京語言大學 也屬於翻來覆去型的.改校名固然有著語言習慣的原因,但更主要的原因卻是季羨林先生曾經指出的,語言本身就是文化的重要組成部分,語言文化 並列本身就不妥當.為了向 知名 大學靠攏,更為了糾正語法錯誤.所以改了 作為乙個語言學校,此等語法錯誤多年了才引起...