+ 1

Anyone can fix it for 2 digit integer

https://code.sololearn.com/c9CXVHsrziMe/?ref=app

17th Nov 2023, 4:15 PM
Sahil
Sahil - avatar
8 Antworten
+ 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.
18th Nov 2023, 4:48 AM
Imara Mohideen
Imara Mohideen - avatar
+ 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.
18th Nov 2023, 4:49 AM
Imara Mohideen
Imara Mohideen - avatar
+ 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.
17th Nov 2023, 6:12 PM
Jan
Jan - avatar
+ 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.
17th Nov 2023, 9:23 PM
Jan
Jan - avatar
+ 1
Ok thanks for try question
18th Nov 2023, 2:04 AM
Sahil
Sahil - avatar
+ 1
Hi
18th Nov 2023, 7:43 PM
Massine Chdni
Massine Chdni - avatar
0
Thanks I solved this question by using space in 1 digit number https://code.sololearn.com/cNyRSAupGhjq/?ref=app
18th Nov 2023, 4:59 AM
Sahil
Sahil - avatar
0
Way
18th Nov 2023, 7:43 PM
Massine Chdni
Massine Chdni - avatar