• 链表 编写链表将数字倒序输出的C语言程序。(我们C语言老师讲的!)


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

    struct shao{
    int num;
    struct shao *next;
    };

    void main()
    {
    int n;
    struct shao *head=NULL,*p1,*p2;

    printf("请输入要参加几个数:");
    scanf("%d",&n);

    while(n<=0)
    {
    printf("错误!请重新输入:");
    scanf("%d",&n);
    }

    p1=(struct shao*)malloc(sizeof(struct shao));
    p1->next=NULL;
    head=p1;
    printf("请输入一个数:");
    scanf("%d",&p1->num);

    for(int i=2;i<=n;i++)
    {
    p2=(struct shao*)malloc(sizeof(struct shao));
    printf("请输入一个数:");
    scanf("%d",&p2->num);
    head=p2;

    p2->next=p1;
    p1=p2;
    }

    printf("倒序的结果是:");
    for(i=0;head!=NULL;i++)
    {
    printf("%d ",head->num);
    head=head->next;
    }
    printf("\n");
    }

  • 相关阅读:
    银行代码
    c#第二章
    c#第一章
    S1304HTML内测测试分析
    HTML第九章
    HTML第八章
    HTML第七章
    Jupyter Notebook与Jupyterhub的安装与配置
    如果你要拍一部微电影
    针对Excel的vbs操作
  • 原文地址:https://www.cnblogs.com/shaoshao/p/2849719.html
Copyright © 2020-2023  润新知