#include <stdio.h>
#include <math.h>
int Primo(int n)
{
if( n == 2 )
return 1;
if( !(n%2) || n == 1 )
return 0;
register int i;
int maxP = (int)ceil(sqrt((double)n));
for(i = 3; i <= maxP; i += 2)
if( !(n % i) )
return 0;
return 1;
}
void DesenharQuadrado( int n )
{
register int i, a;
int count = 1;
//Pergunta ficou ambigua, jeito 1 ou jeito 2?
// // //Jeito 1
// for(i = 0; i < n; i++)
// {
// for(a = 0; a < n; a++, count++)
// if( Primo(count) )
// printf("#");
// else
// printf("_");
// printf("\n");
// }
// // // Jeito 2
for(i = 0; i < n; i++)
{
for(a = 1; a <= n; a++)
if( Primo(a) )
printf("#");
else
printf("_");
printf("\n");
}
}
int main()
{
int n;
printf("Digite o tamanho do quadrado\n"); scanf("%d", &n);
DesenharQuadrado(n);
return (0);
}
What... Is the doubt????
– Nexus
I can not print the positions that are prime number, is printing wrong, if you type 5 for example, will not print # in the positions 2, 3 , 5 and so respectively, the doubt is on how to print the positions that are prime number.
– danibrum