#include
#define N 3 //定义学生个数
#define MATH 0
#define ENGLISH 1
#define COMPUTER 2 //定义成绩数组下标,增加程序可读性
typedef struct _Student //定义学生类型
{
long No;
char name[8];
float score[3];
}Student,*PStudent;
int check(PStudent stu) //判断是否有挂科
{
float line = 60.0;
for(int i = 0;i < 3;i ++)
if(stu->score[i] < line) return 0; //低于及格线返回0表示不及格
return 1;
}
void main()
{
Student students[N];
for(int i = 0;i < N;i ++)
{
printf("输入学生%d的信息:\r\n",i+1);
printf("学号:");scanf("%ld",&students[i].No);
printf("姓名:");scanf("%s",&students[i].name);
printf("\r\n数学成绩:");scanf("%f",&students[i].score[MATH]);
printf("英语成绩:");scanf("%f",&students[i].score[ENGLISH]);
printf("计算机成绩:");scanf("%f",&students[i].score[COMPUTER]);
}
printf("------- 不及格的学生 -------\r\n\r\n");
printf("%8s%8s%8s%8s%8s\r\n","学号","姓名","数学","英语","计算机");
for(i = 0;i < N;i ++)
{
if(!check(&students[i]))
{
printf("%8ld",students[i].No);
printf("%8s",students[i].name);
printf("%8.2f",students[i].score[MATH]);
printf("%8.2f",students[i].score[ENGLISH]);
printf("%8.2f",students[i].score[COMPUTER]);
}
printf("\r\n");
}
}
int sum=0,i,j,h;
for(i=1;i<=20;i++)
{
h=1;
for(j=1;j<=i;j++)
{
h=h*j;
}
sum=sum+h;
}
unsigned long long sum=0,i,j,h;
for(i=1;i<=20;i++)
{
h=1;
for(j=1;j<=i;j++)
h*=j;
sum+=h;
}
用Matlab很简单
sum=0;
for i=1:20
sum=sum+prod(1:i);
end
用C的话,一楼就可以了
int i;
double t = 1, sum = 0;
for (i = 1; i <=20; i++)
{
t *= i;
sum += t;
}
/* sum 即所求 */