C语言程序设计精髓第十一周

本文介绍了C语言编程的一些核心练习题目,包括找出字典顺序最小的国名、学生成绩管理系统、月份表示、程序改错、找数组最值、冒泡排序、删除字符串特定字符、求最大数和最小数的最大公约数以及数列合并。每个题目都详细描述了要求和示例运行结果,旨在提升C语言编程技能。
摘要由CSDN通过智能技术生成

练兵区

1. 找出按字典顺序排在最前面的国名(4分)

输入5个国名,编程找出并输出按字典顺序排在最前面的国名。

提示:所谓字典顺序就是将字符串按由小到大的顺序排列,因此找出按字典顺序排在最前面的国名指的就是最小的字符串。

程序的运行结果示例:

Input five countries’ names:

America↙

China↙

Japan↙

England↙

Sweden↙

The minimum is:America

#include <stdio.h>
#include<string.h>
#define N 20
int main()
{
   
    char country[5][N], temp[N];
    int i, j;
    printf("Input five countries' names:\n");
    for(i=0; i<5;i++)
        gets(country[i]);
    for(i=0;i<5;i++)
    {
   
        for(j=i+1;j<5;j++)
        {
   
            if(strcmp(country[i],country[j])>0)
            {
   
                strcpy(temp,country[i]);
                strcpy(country[i],country[j]);
                strcpy(country[j],temp);
            }
        }
    }
    printf("The minimum is:%s\n", country[0]);
    return 0;
}
2. 学生成绩管理系统V2.0(4分)

题目内容:

某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,参考前面章节的“学生成绩管理系统V1.0”,用一维数组和函数指针作函数参数编程实现如下菜单驱动的学生成绩管理系统:

(1)录入每个学生的学号和考试成绩;

(2)计算课程的总分和平均分;

(3)按成绩由高到低排出名次表;

(4)按成绩由低到高排出名次表;

(5)按学号由小到大排出成绩表;

(6)按学号查询学生排名及其考试成绩;

(7)按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;

(8)输出每个学生的学号、考试成绩。

要求程序运行后显示的菜单如下:

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please enter your choice:

然后,根据用户输入的选项执行相应的操作。

程序运行结果示例:

Input student number(n<30):

6↙

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

1↙

Input student’s ID and score:

11003001↙

87↙

11003005↙

98↙

11003003↙

75↙

11003002

48

11003004↙

65↙

11003006↙

100↙

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

2↙

sum=473,aver=78.83

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

3↙

Sort in descending order by score:

11003006 100

11003005 98

11003001 87

11003003 75

11003004 65

11003002 48

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

4↙

Sort in ascending order by score:

11003002 48

11003004 65

11003003 75

11003001 87

11003005 98

11003006 100

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

5↙

Sort in ascending order by number:

11003001 87

11003002 48

11003003 75

11003004 65

11003005 98

11003006 100

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

6↙

Input the number you want to search:

11003004↙

11003004 65

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

7↙

<60 1 16.67%

60-69 1 16.67%

70-79 1 16.67%

80-89 1 16.67%

90-99 1 16.67%

100 1 16.67%

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

8↙

11003001 87

11003002 48

11003003 75

11003004 65

11003005 98

11003006 100

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

9↙

Input error!

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

0↙

End of program!
其实这题里面我没有太理解应该把函数指针用在那里,就随便加了一个。mooc上显示结果错误,但我没找出来。

#include <stdio.h>
#define N 30
void Fun(long number[], float score[], int n, void (*f)(long*, float*, int));
void Descending(long number[], float score[], int n);
void AscendingNum(long number[], float score[], int n);
float Search(long number[], float score[], int n, long search);
void ResultAnalysis(long number[], float score[], int n);
void Ascending(long number[], float score[], int n);
int main( )
{
   
    int n, choice, i;
    long number[N], search;
    float score[N], sum, average, result;
    printf("Input student number(n<30):\n");
    scanf("%d", &n);
    do{
   
        printf("Management for Students' scores\n");
        printf("1.Input record\n");
        printf("2.Caculate total and average score of course\n");
        printf("3.Sort in descending order by score\n");
        printf("4.Sort in ascending order by score\n");
        printf("5.Sort in ascending order by number\n");
        printf("6.Search by number\n");
        printf("7.Statistic analysis\n");
        printf("8.List record\n");
        printf("0.Exit\n");
        printf("Please Input your choice:\n");
        scanf("%d", &choice);
        switch(choice)
        {
   
            case 1:
            {
   
                printf("Input student's ID, name and score:\n");
                for(i=0;i<n;i++)
                {
   
                    scanf("%ld%f", &number[i],&score[i]);
                }
                
                break;
            }
            case 2:
            {
   
                sum = 0;
                average = 0;
                for(i=0;i<n;i++)
                {
   
                    sum+=score[i];
                }
                average = sum/n;
                printf("sum=%.0f,aver=%.2f\n", sum, average);
                break;
                
            }
            case 3:
            {
   
                printf("Sort in descending order by score:\n");
                Fun(number, score, n, Descending);
                break;
            }
            case 4:
            {
   
                printf("Sort in ascending order by score:\n");
                Fun(number, score, n, Ascending);
                break;
            }
            case 5:
            {
   
                printf("Sort in ascending order by number:\n");
                AscendingNum(number, score, n);
                break;
            }
            case 6:
            {
   
                printf("Input the number you want to search:\n");
                scanf("%ld", &search);
                result = Search(number, score, n, search);
                if(result==0)
                    printf("Not found!\n");
                else
                    printf("%ld\t%.0f\n", search, result);
                break;
            }
            case 7:
            {
   
                ResultAnalysis(number, score, n);
                break;
            }
            case 8:
            {
   
                for(i=0;i<n;i++)
                {
   
                    printf("%ld\t%.0f\n", number[i], score[i]);

                }
                break;
            }
            case 0: break;
            default: printf("Input error!\n");
        }
    }while(choice!=0);
    printf("End of program!\n");
    return 0;
}

void Descending(long number[], float score[], int n)
{
   
    int i, j, temp, a;
    for(i=0;i<n-1;i++)
    {
   
        for(j=i+1;j<n;j++)
        {
   
            if(score[i]<score[j])
            {
   
                temp = score[i];
                score[i]=score[j];
                score[j]=temp;
                a = number[i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值