Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 20161017 rawsum columnsum.cpp : 定義主控台應用程式的進入點。
- //
- #include <stdio.h>
- #include<stdlib.h>
- int main()
- {
- int *p = (int *)malloc(sizeof(int) * 25);
- while (1)
- {
- int *rawsum = (int *)calloc(5,sizeof(int));
- int *columnsum = (int *)calloc(5,sizeof(int));
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- if (scanf("%d", p + i * 5 + j) == EOF)return 0;
- }
- }
- for (int j = 0; j < 5; j++)
- {
- for (int raw = 0; raw < 5; raw++)
- {
- *(rawsum + j) += *(p + raw * 5 + j);
- }
- for (int column = 0; column < 5; column++)
- {
- *(columnsum + j) += *(p + j * 5 + column);
- }
- }
- printf("Row totals:");
- for (int i = 0; i < 5; i++)
- printf(" %d", *(columnsum + i));
- printf("\nColumn totals:");
- for (int i = 0; i < 5; i++)
- printf(" %d", *(rawsum + i));
- puts("");
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment