困难——改错题

为什么不复制粘贴题而用图片

答: 图片更原滋原味, 且有些符号不能复制粘贴, 且暂时没有学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;
}

3

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值