Guest User

Untitled

a guest
Apr 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void matrica(int iMaxRed,int iMaxKol);
  5.  
  6. int main()
  7. {
  8.     FILE *fIN,*fOUT;
  9.     int iMaxRed,iMaxKol;
  10.  
  11.     fIN=fopen("test.in","r");
  12.     fOUT=fopen("test.out","w");
  13.  
  14.     fscanf(fIN,"%d%d",&iMaxRed,&iMaxKol);
  15.  
  16.     matrica(iMaxRed,iMaxKol);
  17.  
  18.     fclose(fIN);
  19.     fclose(fOUT);
  20.  
  21.     return 0;
  22. }
  23.  
  24. void matrica(int iMaxRed,int iMaxKol)
  25. {
  26.     FILE *fIN,*fOUT;
  27.     int aiMat[iMaxRed][iMaxKol],iBrojac1,iBrojac2,iSumRed[iMaxRed],iSumKol[iMaxKol];
  28.  
  29.     memset(iSumRed,0,sizeof(iSumRed));
  30.     memset(iSumKol,0,sizeof(iSumKol));
  31.  
  32.     fIN=fopen("test.in","r");
  33.     fOUT=fopen("test.out","w");
  34.  
  35.     fscanf(fIN,"%d%d",&iMaxRed,&iMaxKol);
  36.  
  37.     for (iBrojac1=0;iBrojac1<iMaxRed;iBrojac1++)
  38.     {
  39.         for (iBrojac2=0;iBrojac2<iMaxKol;iBrojac2++)
  40.         {
  41.             fscanf(fIN,"%d",&aiMat[iBrojac1][iBrojac2]);
  42.         }
  43.     }
  44.     for (iBrojac1=0;iBrojac1<iMaxRed;iBrojac1++)
  45.     {
  46.         for (iBrojac2=0;iBrojac2<iMaxKol;iBrojac2++)
  47.         {
  48.             iSumRed[iBrojac1]+=aiMat[iBrojac1][iBrojac2];
  49.             iSumKol[iBrojac2]+=aiMat[iBrojac2][iBrojac1];
  50.         }
  51.     }
  52.     for (iBrojac1=0;iBrojac1<iMaxRed;iBrojac1++)
  53.     {
  54.         printf("%3d",iSumRed[iBrojac1]);
  55.         fprintf(fOUT,"%3d",iSumRed[iBrojac1]);
  56.     }
  57.     printf("\n");
  58.     fprintf(fOUT,"\n");
  59.     for (iBrojac1=0;iBrojac1<iMaxKol;iBrojac1++)
  60.     {
  61.         printf("%3d",iSumKol[iBrojac1]);
  62.         fprintf(fOUT,"%3d",iSumKol[iBrojac1]);
  63.     }
  64.     printf("\n");
  65.     fprintf(fOUT,"\n");
  66.  
  67.     fclose(fIN);
  68.     fclose(fOUT);
  69. }
Add Comment
Please, Sign In to add comment