为什么不复制粘贴题而用图片
答: 图片更原滋原味, 且有些符号不能复制粘贴, 且暂时没有学latex的必要性.
艸, 开什么玩笑中等改错题有30道, 困难改错题就2两道?
1.
#include <stdio.h>
#define SIZE 10 //
main( )
{ int i, j, t, a[SIZE];
printf("input 10 numbers: \n");
for(i = 0;i < SIZE;i++)
scanf("%d", &a[i]); //
printf("\n");
for (i = 0; i< SIZE; i++)
for (j = SIZE - 1; j >= i + 1; j--)
{
if (a[j] < a[j-1]) //
{
t=a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
for (i = 0; i < SIZE; i++)
printf("%d\n", a[i]);
}
2
#include <stdio.h>
#define SIZE sizeof(struct node)
#include <stdlib.h> // 包含了malloc.h
struct node
{
long num;
float score;
struct node *next;
}; //
int main()
{
int n = 0;
struct node *head = NULL, *p1, *p2;
p1 = p2 = (struct node*)malloc(SIZE);
printf("Input %d node data:\n", n + 1);
scanf("%d%f", &p1->num, &p1->score);
while (p1->num != 0)
{
if (++n == 1)
head = p1;
else
p2->next = p1;
p2 = p1; //
p1 = (struct node*)malloc(SIZE);
printf("Input %d node data:\n", n + 1);
scanf("%d%f", &p1->num, &p1->score); // 优先级问题?
}
p2->next = NULL; // 后面有啊
free(p1);
printf("Prit list:\n");
p2->next = NULL;
if (head != NULL)
{
p1=head;
while (p1 != NULL)
{
printf("num:%d\tscore:%.2f\n", p1->num, p1->score);
p1 = p1->next;
}
}
return 0;
}