6-1 计算两个复数之积
struct complex multiply(struct complex x, struct complex y)
{
struct complex product;
product.real = x.real * y.real - x.imag * y.imag;
product.imag = x.real * y.imag + x.imag * y.real;
return product;
}
6-2 结构体数组中查找指定编号人员
struct student fun(struct student* std, char* num)
{
struct student product;
for (int i = 0; i < 8; i++)
{
if (std[i].num[0] == num[0])
product = std[i];
}
return product;
}
6-3 综合成绩
文章来源:https://www.toymoban.com/news/detail-767323.html
double getAverage(Applicant* a)
{
double sum = 0.0;
sum = a->computational * 1.0 * 0.4 + a->humanistic * 1.0 * 0.5 + a->logical * 1.0 * 0.3 + a->presentation * 1.0 * 0.6 + a->scientific * 1.0 * 0.8;
return sum;
}
6-4 结构体数组按总分排序
文章来源地址https://www.toymoban.com/news/detail-767323.html
void calc(struct student* p, int n)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 3; j++)
{
p[i].sum += p[i].score[j];
}
}
}
void sort(struct student* p, int n)
{
struct student tmp;
for (int i = 0; i < 4; i++)
{
for (int j = i+1; j < 5; j++)
{
if (p[i].sum < p[j].sum)
{
tmp = p[j];
p[j] = p[i];
p[i] = tmp;
}
}
}
}
到了这里,关于【C/PTA —— 14.结构体1(课内实践)】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!