We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C
- Functions
- Students Marks Sum
- Discussions
Students Marks Sum
Students Marks Sum
Sort by
recency
|
523 Discussions
|
Please Login in order to post a comment
include
include
include
include
//Complete the following function.
int marks_summation(int* marks, int number_of_students, char gender) { int sum=0; if(gender=='b') { for(int i=0; i<=number_of_students; i+=2) { sum+=marks[i]; } return sum; } else { for(int i =1;i<=number_of_students;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; }
Can someone please explain me this question ?
shortest way to do this is probably