0
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(){
short int numCasos, i = 1, j = 1, soma = 0;
long long int num;
scanf("%hd", &numCasos);
while(i <= numCasos){
scanf("%lld", &num);
while(j <= num){
if(num % j == 0) soma++;
j++;
}
if(soma == 2) printf("%lld eh primo\n", num);
else printf("%lld nao eh primo\n", num);
soma = 0;
j = 1;
i++;
}
return 0;
}
Description of the problem:
In mathematics, a Prime Number is one that can be divided only by 1 (one) and by itself. For example, the number 7 is prime, as it can be divided only by the number 1 and the number 7. Entree
The entry contains several test cases. The first line of the input contains an integer N (1 N 100), indicating the number of test cases of the input. Each of the following lines contains an integer value X (1 < X 107), which may or may not be a prime number. Exit
For each input test case, print the message "X is prime" or "X is not prime", according to the supplied specification.
Where is the variable "num" being incremented? Is it not lost in the second "while"?
– Rodrigo Tognin
@Rodrigotognim: the variable "num" is assigned a value with "scanf".
– pmg
long long is a novelty of C99. Maybe Uri’s compiler is a C89 compiler and gives compilation error (not Runtime error).
– pmg
That was the problem, the long long, the Uri should not accept, I used unsigned long and it worked! Thank you guys!
– Thiago Prestes