【程式1】
題目:編寫input()和output()函式輸入,輸出5個學生的資料記錄。(用結構體設計,學生記錄中包括學號、姓名、四門課程成績)
程式源**:
#include
#define n 5
struct student
stu[n];
void input(struct student stu);
void print(struct student stu);
void main()
void input(struct student stu)
printf("\n");
}}void print(struct student stu)
}【程式2】
建立100名學生的資訊表,每個學生的資料報括學號、姓名、及一門課的成績,要求從鍵盤輸入這100名學生的資訊,並按照每一行顯示一名學生資訊的格式將他們的資訊顯示出來。
#include
#define n 3
struct student
; void main()
printf("number: name: score:\n");
for(i=0;i printf("%-8d%-10s%d\n",s[i].num,s[i].name,s[i].score);
}【程式3】
題目:建立乙個鍊錶。
程式源**:
/*creat a list*/
#include "stdlib.h"
#include
#define n 3
struct list
;typedef struct list node;
typedef node *link;
void main()
ptr=head;
while(ptr!=null)
}【程式4】
題目:反向輸出乙個鍊錶。
1.程式分析:
2.程式源**:
/*reverse output a list*/
#include "stdlib.h"
#include
struct list
;typedef struct list node;
typedef node *link;
void main()
ptr=ptr->next;
while(ptr!=null)
}【程式5】
已有a,b兩個鍊錶,每個鍊錶中的的結點包括學號、成績。要求把兩個鍊錶合併,按學號公升序排列
#include
#include
typedefstructstudent
stu;
stu*create()
if(head==null)
head=p;
else
tail->next=p;
tail=p;
}returnhead;
}voidoutput(stu*p)
}stu*link(stu*p1,stu*p2)
else
while(p1!=null&&p2!=null)
else
}if(p1!=null)
p->next=p1;
else
p->next=p2;
returnhead;
}intmain(intargc,char*ar**)
【程式6】13個人轉成一圈,從第乙個人開始報數,報到3的退出,問最後退出的人原來的序號。(用鍊錶實現)
#include
#include
#define len sizeof(struct student)
struct student{
綜合程式設計題及解答
1 設計乙個類rect,要求如下 1 該類中的私有資料成員length,width存放它的長和寬,並且設定它們的預設值是0。2 通過成員函式設定其長和寬,並確保長和寬都在 0,50 範圍之內。3 實現求周長函式getperimeter 解 程式設計如下 include using namespace...
實驗4 迴圈結構程式設計1題目及解答
4.3 迴圈結構程式設計1 1 題中頁碼均為 c語言程式設計教程 中的頁碼 2 題後為原程式檔名 3 僅提交名為 c 的源程式檔案,可一起提交,也可逐題提交 1 按照右邊給出的流程圖用while語句求1 100之間的偶數之和。007張三t411.c,007張三t412.c 提示 參見p89 例4.1...
C語言程式設計練習題之陣列與結構體
在每小題列出的四個備選項中只有乙個是符合題目要求的。1 若有定義int a 4 則a a 0 2 a 2 a 3 等於 a 1 b 2 c 3 d 4 2 設有陣列定義 char array china 則陣列 array所佔的空間為 a 4個位元組 b 5個位元組 c 6個位元組 d 7個位元組 ...