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

这篇博客介绍了C语言编程实践,包括有趣的回文检测、学生成绩管理系统V1.0等多个编程题目,涵盖了字符串处理、数组操作和数据管理等方面的知识。通过实例展示了如何实现这些功能,如回文判断、成绩录入、排序和统计分析等。
摘要由CSDN通过智能技术生成

练兵区

1. 有趣的“回文”检测

题目内容:

英文中有很多的回文词,回文词的拼法十分有趣,无论是从前往后拼读,还是从后往前拼读,他们的拼法和词义都不变。例如:dad(爸爸),mum(妈妈),noon(中午),eve(前夕),eye(眼睛),pop(流行),deed(行为),level(水平)等。简单地说,“回文”就是指顺读和倒读都一样的字符串。现在请你编程输入一个单词,判断它是否是回文。

提示:

(1)设置两个指针pStart和pEnd,让pStart指向字符串首部,让pEnd指向字符串尾部。

(2)利用循环从字符串两边对指针所指字符进行比较,当对应的两字符相等且两指针未超越对方时,使指针pStart向前移动一个字符位置(加1),使指针pEnd向后移动一个字符位置(减1),一旦发现两字符不等或两指针已互相超越(不可能是回文),则立即停止循环。

(3)根据退出循环时两指针的位置,判断字符串是否为回文。

程序的两次运行结果如下:

第1次

Input string:ABCCBA↙

Yes!

第2次

Input string:student↙

No!

#include <stdio.h>
#define N 100
int main( )
{
      
    char a[N];
    char *pStart, *pEnd;
    printf("Input string:");
    scanf("%s", a);
    pStart = a;
    pEnd = a;
    while(*pEnd!='\0')
        pEnd++;
    pEnd--;
    while(pEnd-pStart>1)
    {
   
        if(*pStart!=*pEnd)
        {
   
            printf("No!\n");
            return 0;
        }
        pEnd--;
        pStart++;
    }
    printf("Yes!\n");
    return 0;
}

2. 学生成绩管理系统V1.0

题目内容:

某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,用一维数组作函数参数编程实现如下学生成绩管理:

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

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

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

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

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

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

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

程序运行结果示例:

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 number

5.Search by number

6.Statistic analysis

7.List record

0.Exit

Please Input your choice:

1↙

Input student’s ID, name 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 number

5.Search by number

6.Statistic analysis

7.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 number

5.Search by number

6.Statistic analysis

7.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 number

5.Search by number

6.Statistic analysis

7.List record

0.Exit

Please Input your choice:

4↙

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 number

5.Search by number

6.Statistic analysis

7.List record

0.Exit

Please Input your choice:

5↙

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 number

5.Search by number

6.Statistic analysis

7.List record

0.Exit

Please Input your choice:

6↙

<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 number

5.Search by number

6.Statistic analysis

7.List record

0.Exit

Please Input your choice:

7↙

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 number

5.Search by number

6.Statistic analysis

7.List record

0.Exit

Please Input your choice:

8↙

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 number

5.Search by number

6.Statistic analysis

7.List record

0.Exit

Please Input your choice:

0↙

End of program!

#include <stdio.h>
#define N 30
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);
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 number\n");
        printf("5.Search by number\n");
        printf("6.Statistic analysis\n");
        printf("7.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");
                Descending(number, score, n);
                break;
            }
            case 4:
            {
   
                printf("Sort in ascending order by number:\n");
                AscendingNum(number, score, n);
                break;
            }
            case 5:
            {
   
                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 6:
            {
   
                ResultAnalysis(number, score, n);
                break;
            }
            case 7:
            {
   
                for(i=0;i<n;i++)
                {
   
                    printf("%ld\t%.0f\n", number[i], score[i]);

                }
                break;
            }
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值