C语言每日一练7.28

B类

1.(原创)请编写一个程序,打印以下图形:

2.(原创)下列程序运行结果为:

#include <stdio.h>
struct haha {
    int num;
    int digit;
    int space;
};
int main() {
    struct haha gh[8] = {{6, 0, 0}, {7, 0, 0},
        {0, 0, 1}, {21, 0, 0}, {5, 1, 0}, {8, 1, 0},
        {7, 1, 0}, {-1, 0, 0}};
    struct haha *p = gh;
    while (p -> num > -1) {
        if (p -> digit) {
            putchar('0' + p -> num);
        } else if (p -> space) {
            putchar(' ');
        } else {
            putchar('a' + p -> num);
        }
        p++;
    }
    putchar('\n');
    return 0;
}

B+类

3.(原创)请编写一个程序,用链表的形式存储用户录入的学生信息并打印,如图所示

-----------------------------以下为答案---------------------------------

 

 

 

 

 

 

 

 

 

1. 

#include <stdio.h>
int main() {
    int i, j;
    for (i = 0; i < 27; i++) {
        for (j = 0; j < i; j++) {
            putchar('Z' - i + j + 1);
        }
        for (j = 0; j < 26 - i; j++) {
            putchar('A' + j);
        }
        putchar('\n');
    }
    return 0;
}

2. gh v587

3. 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
    char name[20];
    float score;
    struct Student *next;
};
typedef struct Student stu;
int main() {
    int i = 0;
    stu *head = NULL, *now, *prev;
    while (1) {
        i++;
        printf("请输入第%d位同学的姓名:", i);
        now = (stu *)malloc(sizeof(stu));
        gets(now -> name);
        if (strcmp(now -> name, "end") == 0) {
            prev -> next = NULL;
            break;
        }
        printf("请输入第%d位同学的成绩:", i);
        scanf("%f", &now -> score);
        getchar();
        if (head == NULL) {
            head = now;            
        } else {
            prev -> next = now;  
        }
        prev = now;
    }
    printf("------------------------\n");
    printf("用户录入的信息如下:\n");
    now = head;
    while (now) {
        printf("姓名:%s\t", now -> name);
        printf("成绩:%.1f\n", now -> score);
        prev = now;
        now = now -> next;
        free(prev);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值