Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void writeToFile() {
- FILE *f = fopen("input.txt", "w");
- char c;
- while((c = getchar()) != '#') {
- fputc(c, f);
- }
- fclose(f);
- }
- void printFile() {
- FILE *f=fopen("output.txt","r");
- char line[100];
- while(!feof(f)){
- fgets(line,100,f);
- if (feof(f))
- break;
- printf("%s",line);
- }
- fclose(f);
- }
- int main() {
- writeToFile();
- int n, i,j;
- int matrica[100][100];
- int sum = 0;
- FILE * inputFile = fopen("input.txt", "r");
- FILE * outputFile = fopen("output.txt", "w");
- fscanf(inputFile, "%d\n", &n);
- for (i=0;i<n;i++) {
- for (j=0;j<n;j++) {
- fscanf(inputFile, "%d", &matrica[i][j]);
- if (i==j) {
- sum+=matrica[i][j];
- }
- }
- }
- for (i=0;i<n;i++) {
- for (j=0;j<n;j++) {
- if (j>i) {
- fprintf(outputFile, "%03d ", sum);
- }
- else
- fprintf(outputFile, " ");
- }
- fprintf(outputFile, "\n");
- }
- fclose(inputFile);
- fclose(outputFile);
- printFile();
- //fclose(inputFile);
- //fclose(outputFile);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement