juinda

Untitled

Oct 25th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // 20161017 rawsum columnsum.cpp : 定義主控台應用程式的進入點。
  2. //
  3.  
  4. #include <stdio.h>
  5. #include<stdlib.h>
  6.  
  7.  
  8. int main()
  9. {
  10. int *p = (int *)malloc(sizeof(int) * 25);
  11. while (1)
  12. {
  13. int *rawsum = (int *)calloc(5,sizeof(int));
  14. int *columnsum = (int *)calloc(5,sizeof(int));
  15. for (int i = 0; i < 5; i++)
  16. {
  17. for (int j = 0; j < 5; j++)
  18. {
  19. if (scanf("%d", p + i * 5 + j) == EOF)return 0;
  20. }
  21. }
  22. for (int j = 0; j < 5; j++)
  23. {
  24. for (int raw = 0; raw < 5; raw++)
  25. {
  26. *(rawsum + j) += *(p + raw * 5 + j);
  27. }
  28. for (int column = 0; column < 5; column++)
  29. {
  30. *(columnsum + j) += *(p + j * 5 + column);
  31. }
  32. }
  33. printf("Row totals:");
  34. for (int i = 0; i < 5; i++)
  35. printf(" %d", *(columnsum + i));
  36. printf("\nColumn totals:");
  37. for (int i = 0; i < 5; i++)
  38. printf(" %d", *(rawsum + i));
  39. puts("");
  40. }
  41. system("pause");
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment