Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- #define colCount 3
- int main()
- {
- int** examMatrix;
- int rowCount;
- int row, col;
- setlocale(LC_ALL, "rus");
- printf("введите количество студентов: ");
- scanf("%d", &rowCount);
- examMatrix = (int**)malloc(sizeof(int*) * rowCount);
- if(examMatrix == NULL)
- {
- return 5;
- }
- for(row = 0; row < rowCount; ++row)
- examMatrix[row] = (int*)malloc(sizeof(int) * colCount);
- if(examMatrix[row] == NULL)
- {
- for(--row; row >= 0; row--)
- {
- free(examMatrix[row]);
- }
- free(examMatrix);
- return 5;
- }
- printf("введите оценки по каждому экзамену. столбцы - экзамены, строки - студенты:\n");
- for(row = 0; row < rowCount; ++row)
- {
- for(col = 0; col < colCount; col++)
- {
- scanf("%d", &examMatrix[row][col]);
- }
- }
- int grades[colCount][5] = { 0 };
- for(row = 0; row < rowCount; ++row)
- {
- for(col = 0; col < colCount; ++col)
- {
- grades[col][examMatrix[row][col] - 1]++;
- }
- }
- printf("\nоценки:\n");
- char* gradeStrings[] = {"неявка", "неудовлетворительно", "удовлетворительно", "хорошо", "отлично"};
- for(col = 0; col < colCount; col++)
- {
- printf("\nоценки по предмету %d:", col);
- for(row = 0; row < 5; row++)
- {
- printf("%s - %d, ", gradeStrings[row], grades[col][row]);
- }
- printf("\n");
- }
- for(row = 0; row < rowCount; row++)
- {
- free(examMatrix[row]);
- }
- free(examMatrix);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement