Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- #include <stdio.h>
- #include <string.h>
- #define MAX_BALL 5
- struct student {
- char name[256];
- char surname[256];
- int ball[5];
- };
- void averagePrint(struct student *students);
- void Print(struct student *students);
- int main() {
- struct student persons[2];
- int n = 2, i;
- for (i=0; i<n; i++) {
- printf("Please enter the name and surname of the person #%d: ", i+1);
- scanf("%s %s", persons[i].name, persons[i].surname);
- for (int j=0; j<5; j++)
- persons[i].ball[j] = 40+rand()%100;
- }
- Print(persons);
- printf("\n");
- averagePrint(persons);
- return 0;
- }
- void Print(struct student *students)
- {
- int n = 2;
- for (int i =0; i<n; i++) {
- printf("Name: %s. SurName: %s. Balls: ", students[i].name, students[i].surname);
- for (int j=0; j<MAX_BALL; j++)
- printf("%d\t", students[i].ball[j]);
- printf("\n");
- }
- }
- void averagePrint(struct student *students)
- {
- int n = 2;
- float sum = 0;
- float arrAverage[2];
- for (int i=0; i<n; i++) {
- sum = 0;
- for (int j=0; j<MAX_BALL; j++)
- sum += students[i].ball[j];
- arrAverage[i] = sum / MAX_BALL;
- }
- for (int i=0; i<n; i++) {
- printf("Name: %s. SurName: %s. Average: ", students[i].name, students[i].surname);
- printf("%f\t", arrAverage[i]);
- printf("\n");
- }
- float total = 0;
- for (int i=0; i<n; i++) {
- total += arrAverage[i];
- }
- printf("\n Average group: %f", total / 2);
- }
Advertisement
Add Comment
Please, Sign In to add comment