[1] Students Marks Sum
잠깐 이해가 안갔는데, 중요한건 상황을 의미하는 첫 문장이었다.
- The alternating elements , , and so on denote the marks of boys.
- Similarly, , , and so on denote the marks of girls.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int marks_summation(int* marks, int number_of_students, char gender){
int sum=0;
for (int i = (gender=='b'?0:1);i<number_of_students;i=i+2)
sum += *(marks+i);
return sum;
}
int main() {
int number_of_students;
char gender;
int sum;
scanf("%d", &number_of_students);
int *marks = (int *) malloc(number_of_students * sizeof (int));
for (int student = 0; student < number_of_students; student++) {
scanf("%d", (marks + student));
}
scanf(" %c", &gender);
sum = marks_summation(marks, number_of_students, gender);
printf("%d", sum);
free(marks);
return 0;
}
'Engineering(SoC Design) > C, C++, Rust' 카테고리의 다른 글
c++를 이용한 동적할당. (0) | 2022.03.11 |
---|---|
C 환경설정 에러 (0) | 2022.03.11 |
메모리가 관리되어야 하는 이유 (0) | 2022.03.06 |
CLI, Command Line Development Tools (0) | 2022.03.06 |
[프로젝트] 메모리관리자 구현 (0) | 2022.03.06 |