I have the following program that checks if a number and the sum of its digits is prime. I would like some advice on how to make it more efficient.
The problem MUST USE the function bool es_primer_perfecte(int n) and the code in int main () CANNOT BE CHANGED
For easier programming comprehension: bool primer (int n) this checks if a number is prime. bool es_primer_perfecte(int n) sends input to check if it is prime. If it is prime, sum the digits of the input into a variable called "resultat" (resultat = result) and check if "resultat" is prime.
Anyways, how do you expect someone to help you if your code is full of foreign languages? You will be very likely ignored.
You can guess what each function is doing if you follow the logic. Even the name of the function is vaguely similar to English. You don't need to be able to understand the language to be able to know what the function is doing. The intent is as clear as day in each function.
Anyway, I've added a timer to test your program and I don't think you can make it any faster.
Come on, I think that my explanation was clear enough:
I have the following program that checks if a number and the sum of its digits is prime.
What you do not understand about my explanation? Anyway, changed main post with some extra information about my code.
There has to be a way to make it faster because if there was not, my program would have been accepted and that's not the case. What I could only think off is the following but it will not make a big change in execution time:
Changing this:
1 2 3 4 5
while (n != 0) {
int copy_n = n%10;
resultat += copy_n;
n /= 10;
}