69 lines
1.4 KiB
C
69 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
|
|
#define QUESTIONS_NUM 10
|
|
|
|
bool isPrime(int num)
|
|
{
|
|
for (int i = 2; i < num; i++)
|
|
{
|
|
if (num % i == 0 && i != num)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
|
|
int H = 0, W = 0;
|
|
printf("Digite a altura da matrix: ");
|
|
if (scanf("%d", &H) != 1)
|
|
{
|
|
return EXIT_FAILURE;
|
|
}
|
|
printf("Digite a largura da matrix: ");
|
|
if (scanf("%d", &W) != 1)
|
|
{
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
int matrix[H][W], primesNumbers = 0;
|
|
for (int i = 0; i < H; i++)
|
|
{
|
|
for (int j = 0; j < W; j++)
|
|
{
|
|
printf("mat[%d][%d]: ", i, j);
|
|
if (scanf("%d", &matrix[i][j]) != 1)
|
|
{
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
if (isPrime(matrix[i][j]) == true)
|
|
{
|
|
primesNumbers++;
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("Matrix %dx%d:\n", H, W);
|
|
for (int i = 0; i < H; i++)
|
|
{
|
|
for (int j = 0; j < W; j++)
|
|
{
|
|
printf("%4d ", matrix[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
int perc = (primesNumbers / (H * W)); // ERROR: For some reason this becomes 0
|
|
if (perc >= 0.7) {
|
|
printf("FARMOU AURA! >:D | Porcentagem de primos: %d%%", perc);
|
|
} else {
|
|
printf(":c | Porcentagem de primos: %d%%", perc);
|
|
}
|
|
}
|