Skip to content

Instantly share code, notes, and snippets.

@peterbrendel
Created November 3, 2016 06:48
Show Gist options
  • Save peterbrendel/1dfd4f64f3493221cf6cc8408019a9ce to your computer and use it in GitHub Desktop.
Save peterbrendel/1dfd4f64f3493221cf6cc8408019a9ce to your computer and use it in GitHub Desktop.
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main()
{
FILE * printarg;
FILE * printtam;
int tamanho;
while((scanf("%d", &tamanho)) && tamanho > 0 && tamanho <=15 ){
printarg = fopen("printarg.txt","w+");
printtam = fopen("printtam.txt","w+");
int tamspacepow=1, tamspace=0;
char arg[50], printargstr[50];
//====================================//
//Define tamanho do argumento "%d"
//Para ser usado dentro do printf
tamspacepow = pow(4,tamanho);
rewind(printtam);
fprintf(printtam,"%d", tamspacepow);
rewind(printtam);
fscanf(printtam, "%s", arg);
tamspace = strlen(arg);
//Define a string dos printf
rewind(printarg);
fprintf(printarg, "%%%dd", tamspace);
rewind(printarg);
fscanf(printarg, "%s", printargstr);
//====================================//
//Printa a matriz com o tamanho definido
//Pela string printargstr
int k=1, dobra=2;
for(int i=0; i<tamanho; i++){
for(int j=0; j<tamanho; j++){
printf(printargstr, k);
if(j<tamanho-1)
printf(" ");
k*=2;
}
k=dobra;
dobra*=2;
printf("\n");
}
printf("\n");
//Fim do while
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment