+ 1
Anyone can fix it for 2 digit integer
8 Respuestas
+ 2
Sahil
The main issue in your code is that you're using the variable y without initializing it. This can lead to undefined behavior because the value of y is unpredictable.
To check if a number is prime, you typically use a loop to iterate from 2 to the square root of the number and check if any of those numbers divide it evenly. Additionally, you need to handle the case when the input is less than or equal to 1, as numbers less than or equal to 1 are not prime.
+ 2
Ensure `y` is initialized (e.g., set `y = 2`), then use a loop to check divisibility by `y` up to the square root of `x`. If divisible, set a flag (`isPrime`) to false and break the loop. After the loop, handle the case when `x` is less than or equal to 1. Finally, based on the `isPrime` flag, print whether `x` is prime or not.
+ 1
I think you should incorporate the classic while loop that reverses an integer value, but I don't have time to deal with your code right now.
+ 1
Sahil I have had a little closer look at your solution now, and there is actually nothing wrong with it, because when you enter 2 as input, then 2 is supposed to be the midpoint between 1 and 1 in order to create a palindrome in the pyramid structure, so there is actually nothing to fix anyway.
+ 1
Ok thanks for try question
+ 1
Hi
0
Thanks I solved this question by using space in 1 digit number
https://code.sololearn.com/cNyRSAupGhjq/?ref=app
0
Way