ivanakarpuzova

Untitled

May 28th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. //Vasiot indeks zapisete go kako vrednost na outName
  3. const char outName[] = "163054.txt";
  4.  
  5.  
  6. void printFile() {
  7. FILE *f=fopen(outName, "r");
  8. char c;
  9. while((c = fgetc(f)) != EOF) {
  10. putchar(c);
  11. }
  12. fclose(f);
  13. }
  14.  
  15.  
  16. void writeToFile() {
  17. FILE *f = fopen("matricaIn.txt", "w");
  18. char c;
  19. while((c = getchar()) != EOF) {
  20. fputc(c, f);
  21. }
  22. fclose(f);
  23. }
  24.  
  25.  
  26. int main() {
  27.  
  28. writeToFile();
  29. printFile();
  30. // Vasiot kod pocnuva od tuka
  31. FILE* fp = fopen("matricaIn.txt", "r");
  32. FILE* out = fopen(outName, "w");
  33. int i,j;
  34. int n;
  35. int matrica[100][100];
  36.  
  37. fscanf(fp, "%d", &n);
  38. for(i = 0; i < n && !feof(fp); i++){
  39. for(j = 0; j < n && !feof(fp); j++){
  40. fscanf(fp, "%d", &matrica[i][j]);
  41. }
  42. }
  43.  
  44. int b[100][100];
  45.  
  46. for(i=0;i<n;i++){
  47. for(j=0;j<n;j++){
  48. if(i==j){
  49. b[i][j]= matrica[n-1-i][n-1-j];
  50.  
  51. }
  52. else
  53. b[i][j]=0;
  54.  
  55.  
  56. }}
  57.  
  58. for(i=0;i<n;i++){
  59. for(j=0;j<n;j++){
  60. if(i+j==n-1){
  61. b[i][j]=matrica[i][j];
  62. }
  63. }}
  64.  
  65.  
  66. for(i=0;i<n;i++){
  67. for(j=0;j<n;j++){
  68.  
  69. if(i!=j && i+j!=n-1 && i+j<n-1){
  70. b[i][j]=matrica[i+1][j+1];
  71. }
  72. }}
  73.  
  74. for(i = 0; i < n; i++){
  75. for(j=0; j < n; j++){
  76. if(i!= j && i+j!= n-1 && i+j>n-1){
  77. b[i][j] = matrica[i-1][j-1];
  78. }
  79. }
  80. }
  81.  
  82. for(i = 0; i < n; i++){
  83. for(j=0; j < n; j++){
  84. fprintf(out, "%d ", b[i][j]);
  85. }
  86. fprintf(out, "\n");
  87. }
  88. // do tuka
  89. fclose(out);
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment