Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.2 kB
24
Indexable
Never
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 50

void get_data(char masv[][10], char hoten[][31], double toan[], double ly[], double hoa[], int *n)
{
    int i;
    
    printf("So sinh vien: ");
    scanf("%d%*c", n);
    
    for (i = 0; i < *n; i++)
    {
        printf("Sinh vien %d:\n", i+1);
        printf("Ma SV: ");
        scanf("%[^\n]%*c", masv[i]);
        printf("Ho ten: ");
        scanf("%[^\n]%*c", hoten[i]);
        printf("Diem Toan Ly Hoa: ");
        scanf("%lf %lf %lf%*c", &toan[i], &ly[i], &hoa[i]);
        diemtb[i] = (toan[i] + ly[i] + hoa[i]) / 3;
    }
}

void print_data(char masv[][10], char hoten[][31], double toan[], double ly[], double hoa[], int n)
{
    int i;
    printf("%-10s%-15s%6s%6s%6s\n", "Ma SV", "Ho Ten", "Toan", "Ly", "Hoa");
    for (i = 0; i < n; i++)
        printf("%-10s%-15s%6.2lf%6.2lf%6.2lf\n", masv[i], hoten[i], toan[i], ly[i], hoa[i]);
}

int main()
{
    char masv[MAX_SIZE][10], hoten[MAX_SIZE][31];
    double toan[MAX_SIZE], ly[MAX_SIZE], hoa[MAX_SIZE], diemtb[MAX_SIZE];
    int n;
    
    get_data(masv, hoten, toan, ly, hoa, &n);
    print_data(masv, hoten, toan, ly, hoa, n);
    
    return 0;
}