本文目录一览:
如何用C语言编程出加权移动平均法
#include stdio.h
double WMean(double marks[],double weights[],int size)
{
double MarksWeightageProductSum=0;
double WeightageSum=0;
int i=0;
for(i=0;isize;i++)
{
MarksWeightageProductSum+=marks[i]*weights[i];
WeightageSum+=weights[i];
}
return MarksWeightageProductSum/WeightageSum;
}
int main()
{
double w[]={1,2,3,4};
double m[]={100,78,89,78};
printf("%f\n",WMean(m,w,4));
getch();
return 0;
}
用C语言计算加权分数
本人(无界)用C-Free亲手编写的,亲测可运行
# include stdio.h
struct stu{ //用结构体数组储存学生的成绩和学分
float score; //成绩
float credit; //学分
}Stu[100];
int main()
{
unsigned int x=1,y=0;
//y用于结构体数组Stu,同时用于循环计算该学生成绩
double sxcsum=0,csum=0,sum;
//sxcsum记录所有成绩乘以学分之和
//csum学分之和
//sum加权成绩
printf("提示:输入完后按回车键结束,输入负数代表学生成绩输入完成\n");
while(1) //循环用户输入成绩,直到用户输入完成后结束
{
printf("请输入第%d门课程的成绩:",x);
scanf("%f",Stu[y].score);
getchar(); //吸收回车键字符
if(Stu[y].score0) break; //输入负数结束循环,结束学生输入成绩操作
printf("请输入第%d门课程的学分:",x++);
scanf("%f",Stu[y++].credit);
getchar();
if(Stu[y-1].credit0) break;
}
printf("---输入成绩结束---\n");
for(x=0;xy;x++) //循环计算成绩,直到算完所有课程 ,y变量储存共有多少门课程
{
sxcsum+=Stu[x].score*Stu[x].credit;
csum+=Stu[x].credit;
}
sum=sxcsum/csum;
printf("该学生的加权成绩为:%g\n",sum);
return(0);
}
---“无界”回答---
c语言关于加权平均分计算奖学金的问题
手打的 但没编译检查是否正确- -~
#include stdio.h
#define KECHENG 12
#define JIANGJIN_LINE 82.13
#define JIGE 60
#define KEMU 12
#define TRUE 1
#define FALSE 0
void input_Num(int *Num)
{
printf("input Num \r\n");
scanf("%d",Num);
}
void input_Chengji(int *Xuefen,int *Chengji)
{
int i;
for(i=0;iKEMU;i++)
{
printf("input No. %d Xuefen \r\n",i);
scanf("%d",Xuefen[i]);
printf("input No. %d Chengji \r\n",i);
scanf("%d",Chengji[i]);
}
}
int Sum_Xuefen(int *Xuefen)
{
int Result;
int i;
Result = 0;
for(i=0;iKEMU;i++)
{
Result = Result + Xuefen[i];
}
return Result;
}
int Sum_Chengji(int *Chengji)
{
int Result;
int i;
Result = 0;
for(i=0;iKEMU;i++)
{
Result = Result + Chengji[i];
}
return Result;
}
int Output_JiGeCheck(int *Chengji)
{
int i;
int Result;
Result = TRUE;
for(i=0;iKEMU;i++)
{
if(Chengji[i]60)
{
Result = FALSE;
break;
}
}
return Result;
}
void OutputResult()
{
int T;
int i;
int L;
int chengji[KEMU];
int xuefen[KEMU];
float MaxChengji;
float TempChengji;
MaxChengji = JIANGJIN_LINE;
L = 0;
input_Num(T);
for(i=0;iT;i++)
{
input_Chengji(xuefen[0],chengji[0]);
if(TRUE == Output_JiGeCheck(chengji[0])
{
TempChengji = Sum_Chengji(chengji[0])/Sum_Xuefen(xuefen[0]);
}
if(TempChengji JIANGJIN_LINE)
{
L++;
if(TempChengji MaxChengji)
{
MaxChengji = TempChengji;
}
}
}
printf("%.2f , %d",MaxChengji,L);
}