Advertisement
LegoDrifter

Untitled

Jan 20th, 2021
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void writeToFile() {
  4. FILE *f = fopen("input.txt", "w");
  5. char c;
  6. while((c = getchar()) != '#') {
  7. fputc(c, f);
  8. }
  9. fclose(f);
  10. }
  11.  
  12. void printFile() {
  13.  
  14. FILE *f=fopen("output.txt","r");
  15. char line[100];
  16. while(!feof(f)){
  17. fgets(line,100,f);
  18. if (feof(f))
  19. break;
  20. printf("%s",line);
  21. }
  22. fclose(f);
  23. }
  24.  
  25. int main() {
  26. writeToFile();
  27.  
  28. int n, i,j;
  29. int matrica[100][100];
  30. int sum = 0;
  31.  
  32. FILE * inputFile = fopen("input.txt", "r");
  33. FILE * outputFile = fopen("output.txt", "w");
  34.  
  35. fscanf(inputFile, "%d\n", &n);
  36.  
  37. for (i=0;i<n;i++) {
  38. for (j=0;j<n;j++) {
  39. fscanf(inputFile, "%d", &matrica[i][j]);
  40. if (i==j) {
  41. sum+=matrica[i][j];
  42. }
  43. }
  44. }
  45.  
  46. for (i=0;i<n;i++) {
  47. for (j=0;j<n;j++) {
  48. if (j>i) {
  49. fprintf(outputFile, "%03d ", sum);
  50.  
  51. }
  52. else
  53. fprintf(outputFile, " ");
  54. }
  55. fprintf(outputFile, "\n");
  56. }
  57.  
  58.  
  59. fclose(inputFile);
  60. fclose(outputFile);
  61.  
  62. printFile();
  63.  
  64. //fclose(inputFile);
  65. //fclose(outputFile);
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement