0
Palindrome explain me also this code
C++ Palindrome Numbers If i put this 👇🏻 only test case 2,5,6 and then 1,3,4 case is coming wrong #include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int n,s=0,r; x=n; while(n!=0) { r=n%10; s=s*10+r; n=n/10; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout << n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
6 Respostas
+ 2
hope this helps (for explaination part)
https://youtube.com/watch?v=Lu3IsQscaa0
+ 1
you doesn't return any value from isPalindrome function:
return s == x;
+ 1
Abhishek Bairwa
Because you didn't return anything in your function.
So do this
return (x == s) //which will return true or false.
and change x = n to n = x
https://code.sololearn.com/c9njvS20pMuc/?ref=app
0
... or make n the function argument, and declare x instead of n:
bool isPalindrome(int n)
{
int x,s=0,r;
- 2
import java.util.Scanner; public class Pattern6 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(k + " "); } System.out.println(); } } }
- 2
Explain me the code