复数乘法*and分段统计学生成绩(结构体)

#include 

typedef struct
{
    double rp, ip;
} COMPLEX;

void Input(COMPLEX *p);
void Output(const COMPLEX *p);
COMPLEX Multiply(COMPLEX *p, COMPLEX *q);

int main()
{
    COMPLEX a, b, c;
    Input(&a);
    Input(&b);
    c = 
Multiply(&a, &b)
;
    Output(&c);
    return 0;
}

void Input(COMPLEX *p)
{
    scanf("%lg %lg", 
&(p->rp), &(p->ip)
);
}

void Output(const COMPLEX *p)
{
    printf("%g %g", 
 p->rp, p->ip
);
}

COMPLEX Multiply(COMPLEX *p, COMPLEX *q)
{
    COMPLEX r;
    r.rp = 
(p->rp * q->rp) - (p->ip * q->ip)
;
    r.ip = 
(p->rp * q->ip) + (q->rp * p->ip)
;
    return r;
}

计算两个复数之积

函数接口定义:

 
  

struct complex multiply(struct complex x, struct complex y);

其中struct complex是复数结构体,其定义如下:

 
  

struct complex{ int real; int imag; };

输入样例:

3 4 5 6

输出样例:

(3+4i) * (5+6i) = -9 + 38i

输入n个学生的姓名和百分制成绩,分段统计学生的成绩。

输入格式:

输入在第一行中给出正整数N(1≤n≤100)。随后N行,每行给出一位学生的姓名和成绩,中间以空格分隔。

输出格式:

在一行中顺序输出成绩为80-100分、60-79分、0-59分的学生人数,中间以空格分隔。

输入样例:

5
huanglan 83
wanghai 76
shenqiang 50
zhangfeng 95
zhangmeng 60

输出样例

221

#include 
#define MAXN 10

struct student {
    int num;
    char name[20];
    int score;
    char grade;
};

int set_grade(struct student* p, int n);

int main()
{
    struct student stu[MAXN], * ptr;
    int n, i, count;

    ptr = stu;
    scanf("%d\n", &n);
    for (i = 0; i < n; i++) {
        scanf("%d%s%d", &stu[i].num, stu[i].name, &stu[i].score);
    }
    count = set_grade(ptr, n);
    printf("The count for failed (<60): %d\n", count);
    printf("The grades:\n");
    for (i = 0; i < n; i++)
        printf("%d %s %c\n", stu[i].num, stu[i].name, stu[i].grade);
    return 0;
}

int set_grade(struct student* p, int n)
{
    int count = 0,i=0;
    for (i = 0; i < n; i++)
    {
        if (p[i].score >= 85 && p[i].score <= 100) {
            p[i].grade = 'A';
        }
        else if (p[i].score >= 70 && p[i].score <= 84) {
            p[i].grade = 'B';
        }
        else if (p[i].score >= 60 && p[i].score <= 69) {
            p[i].grade = 'C';
        }
        else if (p[i].score >= 0 && p[i].score <= 59) {
            p[i].grade = 'D';
            count++;
        }
    }
    return count;

}
#include
#define MAXN 100
struct student{
  char name[20];
  int score;
};
void cnt_score( struct student *p, int n );

int main()
{   
  int i, n;
  struct student stu[MAXN];

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s%d", stu[i].name, &stu[i].score);
  } 
  cnt_score(stu, n);

  return 0;
}

void cnt_score(struct student *p, int n)
{   
    int cnt_a = 0, cnt_p = 0, cnt_f = 0;
    
struct student *q = p + n - 1;


    while ( p <= q ){
        if (
if (p->score >= 80)
) cnt_a++;
        else if (
p->score >= 60
) cnt_p++;
        else cnt_f++;
        p++;
    }
    printf("%d %d %d\n", cnt_a, cnt_p, cnt_f);
}

你可能感兴趣的:(前端,服务器,linux)