IB001 – Seminární skupiny 16, 17, 18 a 19

Študent 3 – zdrojový kód

#include <stdio.h>

struct student
{
    char meno[20];
    char priezvisko[20];
    unsigned short uco;
    float priemer;
};

void nacitaj(struct student *stud)
{
    printf("Zadaj meno: ");
    scanf("%19s", stud->meno);
    printf("Zadaj priezvisko: ");
    scanf("%19s", stud->priezvisko);
    printf("Zadaj uco: ");
    scanf("%hu", &stud->uco);
    printf("Zadaj priemer: ");
    scanf("%f", &stud->priemer);
}

void vypis(struct student stud)
{
    printf("%s %s, uco %hu, priemer: %.2f", stud.meno, stud.priezvisko, stud.uco, stud.priemer);
}

int main()
{
    unsigned short pocet;

    printf("Zadaj pocet studentov: ");
    scanf("%hu", &pocet);
    printf("\n");

    struct student studenti[pocet];

    for (unsigned short i = 0; i < pocet; i++)
    {
        nacitaj(&studenti[i]);
        printf("\n");
    }

    printf("Nacitani boli nasledujuci studenti:\n");
    for (unsigned short i = 0; i < pocet; i++)
    {
        vypis(studenti[i]);
        printf("\n");
    }

    unsigned short uco;
    float priemer;
    unsigned short najdeny = 0;

    printf("\nZistenie priemeru\n");
    printf("Zadaj uco: ");
    scanf("%hu", &uco);

    for (unsigned short i = 0; i < pocet; i++)
    {
        if (studenti[i].uco == uco)
        {
            najdeny = 1;
            priemer = studenti[i].priemer;
            break;
        }
    }

    if (najdeny)
    {
        printf("\nStudent s uco %hu ma priemer %.2f.\n", uco, priemer);

    }
    else
    {
        printf("\nStudent so zadanym uco neexistuje.\n");
    }

    return 0;
}