当前位置: 代码迷 >> C语言 >> [求助]怎么用内部变量写程序?
  详细解决方案

[求助]怎么用内部变量写程序?

热度:353   发布时间:2006-12-13 17:28:11.0
[求助]怎么用内部变量写程序?

这个程序能用内部变量写吗,怎么写的啊?,谢谢

#include<stdio.h>
#include<stdlib.h>

void InputScore(void);
void Calculat(void);
void AverageEachStu(void);
void AverageEachCourse(void);
void FindMaxScore(void);
void DisplayScore(void);

int s[1000][6]={0};
long AS[100]={0},AC[6]={0};
long max=0;
long p,q;
int n=0;
int m=1;

int main(void)
{
InputScore();
Calculat();
FindMaxScore();
DisplayScore();

system("PAUSE");
return 0;
}


void InputScore(void) /*数据输入*/
{
printf("学生编号(输入0结束):",m);
scanf("%d",&n);
while(n!=0)
{
s[n][0]=1;
printf("功课1: ");
scanf("%d",&s[n][1]);
printf("功课2: ");
scanf("%d",&s[n][2]);
printf("功课3: ");
scanf("%d",&s[n][3]);
printf("功课4: ");
scanf("%d",&s[n][4]);
printf("功课5: ");
scanf("%d",&s[n][5]);
printf("----------------------------------------------------------------\n");
printf("学生编号(输入0结束):",m=m+1);
scanf("%d",&n);
}
}

void Calculat(void) /*数据计算函数*/
{
AverageEachStu();
AverageEachCourse();
}

void AverageEachStu(void) /*计算每个学生平均分*/
{
int i,j;
for(i=1;i<1000;i++)
{
if(s[i][0])
{
for(j=1;j<6;j++)
{
AS[i]+=s[i][j];
}
AS[i]/=5;
}
}
}

void AverageEachCourse(void) /*计算每科的平均分*/
{
int i,j;

for(i=1;i<=1000;i++)
{
if(s[i][0])
{
for(j=1;j<6;j++)
{
AC[j]+=s[i][j];
}
}
}
for(j=1;j<=6;j++)
{
AC[j]/=(m-1);
}
}

void FindMaxScore(void) /*查找最高分*/
{

int i,j;

for(i=1;i<=1000;i++)
{
if(s[i][0])
{
for(j=1;j<=6;j++)
{
if(max<s[i][j])
{
max=s[i][j];
p=i;
q=j;
}
}
}
}
}

void DisplayScore(void) /*输出结果*/
{
int i;
printf("\n");
printf("学生编号\t功课1\t功课2\t功课3\t功课4\t功课5\t平均分\n");
for(i=0;i<1000;i++)
{
if(s[i][0])
{
printf("%d\t\t%d\t%d\t%d\t%d\t%d\t%d\n",i,s[i][1],s[i][2], s[i][3],s[i][4],s[i][5],AS[i]);
}
}

printf("平均分\t\t%d\t%d\t%d\t%d\t%d\t \n",AC[1],AC[2],AC[3],AC[4],AC[5]);
printf("\n");
printf("最高分对应的学生是: 学生%d\n",p);
printf("最高分对应的功课是: 功课%d\n",q);
printf("\n");
}

搜索更多相关的解决方案: 变量  

----------------解决方案--------------------------------------------------------
[原创]发

#include<stdio.h>
#include<stdlib.h>

void InputScore(int *,int,int );
void Calculat(void);
void AverageEachStu(void);
void AverageEachCourse(void);
void FindMaxScore(void);
void DisplayScore(void);

int main(void)
{
int s[1000][6]={0};
long AS[100]={0},AC[6]={0};
long max=0;
long p,q;
int n=0;
int m=1;
int *p1,
p1=&m;
InputScore(s,p1,n);
Calculat(s,AS,AC,p1);
max=FindMaxScore((&p,&q,s,max);
DisplayScores(s,AC,AS,&p,&q);

system("PAUSE");
return 0;
}


void InputScore(int **s,int *m,int n) /*数据输入*/
{
printf("学生编号(输入0结束):");
scanf("%d",&n);
while(n!=0)
{
s[n][0]=1;
printf("功课1: ");
scanf("%d",&s[n][1]);
printf("功课2: ");
scanf("%d",&s[n][2]);
printf("功课3: ");
scanf("%d",&s[n][3]);
printf("功课4: ");
scanf("%d",&s[n][4]);
printf("功课5: ");
scanf("%d",&s[n][5]);
printf("----------------------------------------------------------------\n");
printf("学生编号(输入0结束):");

*m=*m+1;
scanf("%d",&n);
}

}

void Calculat(int **s,int *AS,int *AC,int *m) /*数据计算函数*/
{
AverageEachStu(s,AS);
AverageEachCourse(s,AC,m);
}

void AverageEachStu(int **s,int *AS) /*计算每个学生平均分*/
{
int i,j;
for(i=1;i<1000;i++)
{
if(s[i][0])
{
for(j=1;j<6;j++)
{
AS[i]+=s[i][j];
}
AS[i]/=5;
}
}
}

void AverageEachCourse(int **s,int *AC,int *m) /*计算每科的平均分*/
{
int i,j;

for(i=1;i<=1000;i++)
{
if(s[i][0])
{
for(j=1;j<6;j++)
{
AC[j]+=s[i][j];
}
}
}
for(j=1;j<=6;j++)
{
AC[j]/=(*m-1);
}
}

int FindMaxScore(int *p,int *q,int **s,int max) /*查找最高分*/
{

int i,j;

for(i=1;i<=1000;i++)
{
if(s[i][0])
{
for(j=1;j<=6;j++)
{
if(max<s[i][j])
{
max=s[i][j];
p=i;
q=j;
}
}
}
}
return max;
}

void DisplayScore(int **s,int *AC,int *AS,int *p,int *q) /*输出结果*/
{
int i;
printf("\n");
printf("学生编号\t功课1\t功课2\t功课3\t功课4\t功课5\t平均分\n");
for(i=0;i<1000;i++)
{
if(s[i][0])
{
printf("%d\t\t%d\t%d\t%d\t%d\t%d\t%d\n",i,s[i][1],s[i][2], s[i][3],s[i][4],s[i][5],AS[i]);
}
}

printf("平均分\t\t%d\t%d\t%d\t%d\t%d\t \n",AC[1],AC[2],AC[3],AC[4],AC[5]);
printf("\n");
printf("最高分对应的学生是: 学生%d\n",*p);
printf("最高分对应的功课是: 功课%d\n",*q);
printf("\n");
}


----------------解决方案--------------------------------------------------------

用带参函数地址传递从main到子函数的引用.


----------------解决方案--------------------------------------------------------

多谢,多谢!


----------------解决方案--------------------------------------------------------

可是警告太多了
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(22) : warning C4024: 'InputScore' : different types for formal and actual parameter 2
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(23) : warning C4047: 'function' : 'int ** ' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(23) : warning C4024: 'Calculat' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(23) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'long '
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(23) : warning C4024: 'Calculat' : different types for formal and actual parameter 2
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(23) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'long '
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(23) : warning C4024: 'Calculat' : different types for formal and actual parameter 3
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(23) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(23) : warning C4024: 'Calculat' : different types for formal and actual parameter 4
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(24) : warning C4047: 'function' : 'int ** ' differs in levels of indirection from 'int [6]'
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(24) : warning C4024: 'FindMaxScore' : different types for formal and actual parameter 3
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(25) : warning C4047: 'function' : 'int ** ' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(25) : warning C4024: 'DisplayScore' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(25) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'long '
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(25) : warning C4024: 'DisplayScore' : different types for formal and actual parameter 2
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(25) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'long '
C:\Program Files\Microsoft Visual Studio\MyProjects\rtr\rtrt.c(25) : warning C4024: 'DisplayScore' : different types for formal and actual parameter 3


----------------解决方案--------------------------------------------------------
  相关解决方案