鱼C论坛

 找回密码
 立即注册
查看: 3798|回复: 5

一道C的程序设计题目,不知道哪儿出错。

[复制链接]
发表于 2013-3-21 12:01:49 | 显示全部楼层 |阅读模式
10鱼币
本帖最后由 Whisper微风 于 2013-3-21 21:55 编辑

#include<stdio.h>
int Iuput_score(int score[])
{
         int i;
          for(i=0;i<30;i++)
           scanf("%d",&score[i]);
          if(score[i]== -1)
           return i;
}


void Output_score(int score[],int n)
{
          int i;
          for(i=0;i<n;i++)
           printf("%d",score[i]);
           printf("%d",n);
}

void store_score(int score[],int n)
{
          int i,j,k;
          for(i=0;i<n-1;i++)
           for(j=0;j<n;j++)
           
             if(score[j]<score[i])
            {
             k=score[i];  
             score[j]=score[i];
              score=k;
            }
  

}

void main()
{
int score[30],n;
printf("please enter the gardes:\n");
n=Iuput_score(score);
store_score(score,n);
Output_score(score,n);

}
[/i][/i]
[i]
[i][i][i][i][i][i]代码如上,我的题目是输入n(n=<30)个学生的成绩(成绩为-1时结束),[/i][/i]
[i][i][i][i][i][i]1统计学生成绩数
2将学生的成绩降序排列
3输出排序后的学生成绩

我真心不知道我的这段代码哪儿出错了 ,希望有大神指导一二,感激不尽


[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]

最佳答案

查看完整内容

#include int score[30],n; int Iuput_score(int score[]) { int i; for(i=0;i
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-3-21 12:01:50 | 显示全部楼层
#include<stdio.h>
int score[30],n;
int Iuput_score(int score[])
{
         int i;
                 for(i=0;i<30;i++){
           scanf("%d",&score[i]);
          if(score[i]== -1)
                          return i;}
}


void Output_score(int score[],int n)
{
          int i;
          for(i=0;i<n;i++)
           printf("%d\t",score[i]);
           printf("\n共有学生%d个",n);
}

void store_score(int score[],int n)
{
          int i,j,k;
          for(i=0;i<n-1;i++)
           for(j=1 + i;j<n;j++)   
             if(score[j]<score[i])
            {
             k=score[i];  
             score[i]=score[j];
              score[j]=k;
            }
  

}

void main()
{

printf("please enter the gardes:\n");
n=Iuput_score(score);
store_score(score,n);
Output_score(score,n);

}

你这段代码里有相当多的错误,有些是逻辑错误,有些是数组写错了,总之很多,
我不知道从哪讲起,我把我改了的发上来了,你对照着看下,有不懂得再问,
但是作为一个初学者,范这些错误是正常的,只有坚持就好了,加油!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-3-21 13:15:30 | 显示全部楼层
非常感谢您的回答  ,呵呵。我会努力的
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-3-21 22:31:10 | 显示全部楼层
void store_score(int score[],int n)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-3-21 22:31:43 | 显示全部楼层
这个错了  你再看看 我现在有点事了  我忙完帮你再看看
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-3-23 17:24:34 | 显示全部楼层
#include<stdio.h>
#include<stdlib.h>
#include<stdio.h>
int Iuput_score(int score[],int w)
{
         int i;
          for(i=0;i<w;i++)
           scanf("%d",&score[i]);
          if(score== -1)
           return i;
}



void Output_score(int score[],int n)
{
          int i;
          for(i=0;i<n;i++)
           printf("%5d",score[i]);
           printf("%d\n",n);
}

void store_score(int score[],int n)
{
          int i,j,k;
          for(i=0;i<n-1;i++)
           for(j=0;j<n;j++)
           
             if(score[j]<score[i])
            {
             k=score[i];  
             score[i]=score[j];
              score[j]=k;
            }
  

}

void main()
{
int score[30],n,w;
printf("请输入你要统计的人数:");
scanf("%d",&w);
printf("please enter the gardes:\n");
n=Iuput_score(score,w);
store_score(score,n);
Output_score(score,n);

}

数组没有输入没有那个下表  我改了一下 可以用了  

排序也有点问题  
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-8-5 10:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表