C程序開發經典實例之8

C程序開發經典實例之8,第1張

C程序開發經典實例之8,第2張

【程序71】
題目:編寫input()和output()函數,輸出五個學生的數據記錄。
1。程序分析:
2。程序源代碼:
# define n5
struct student
{
charnum[6];
char name[8];
int score[4];
} stu[N];
input(stu)
struct stu[];
{
int i,j;
for(I = 0;i {
printf("\n請輸入%d的%d\n",i 1,N);
printf(" num:");
scanf("%s",stu[i]。num);
printf(" name:");
scanf("%s",stu[i]。姓名);
for(j = 0;j {
printf("score %d .",j 1);
scanf("%d",&stu[i]。score[j]);
}
printf(" \ n");
}
}
print(stu)
struct stu[];
{
int i,j;
printf(" \ n沒有。名稱SCO 1 SCO 2 SCO 3 \ n");
for(I = 0;i {
printf("%-6s%-10s",stu[i]。num,stu[i]。姓名);
for(j = 0;jdata = num
ptr-> next =(link)malloc(sizeof(node));
if(I = = 4)ptr-> next = NULL;
else ptr = ptr->next;
}
ptr = head;
while(ptr!= NULL)
{
printf(" value = = > % d \ n",ptr->data);
tr = ptr->next;
}
}

[Program 73]
標題:反曏輸出鏈表。
1。程序分析:
2。程序源代碼:

# include" stdlib . h"
# include" stdio . h"

struct list * next;
};
typedef結搆列表節點;
typedef node * link;
void main()
{
link ptr,head,tail
int num,I;
tail =(link)malloc(sizeof(node));
tail-> next = NULL;
ptr = tail;
printf(" \ n請輸入5個數據= = > \ n");
for(I = 0;i {
scanf("%d",& num);
ptr-> data = num;
head =(link)malloc(sizeof(node));
head-> next = ptr;
ptr = head;
}
ptr = ptr->next;
while(ptr!= NULL)
{
printf(" value = = > % d \ n",ptr->data);
ptr = ptr->next;
}
}

位律師廻複

生活常識_百科知識_各類知識大全»C程序開發經典實例之8

0條評論

    發表評論

    提供最優質的資源集郃

    立即查看了解詳情