How do I break down a user inputted integer to individual digits and store it into my array? I have an if statement that compares the spots of the array to check if it is a palindrome, but I need to make it so the user inputted number is broken up individually into the array. Please break it down into steps so I can understand.
#include<iostream>
using namespace std;
int main()
{
char array[6];
cout << "Enter a single
number:";
cin >> array;
cout << array;
cout << endl;
if ((array[0] == array[5]) && (array[1] ==
array[4]) && (array[2] == array[3]))
cout << "Palindrome";
else
cout << "Not
Palindrome";
}
#include<iostream> using namespace std; int main() { char array[6] = {'0'}; int n, i = 0; cout << "Enter a single number: "; cin >> n; while(n>0){ array[i++] = '0'+(n%10); n = n / 10; } for(i = 0;i<6;i++){ cout<<array[i]<<" "; } cout<<endl; if ((array[0] == array[5]) && (array[1] == array[4]) && (array[2] == array[3])) cout << "Palindrome"; else cout << "Not Palindrome"; return 0; }
Get Answers For Free
Most questions answered within 1 hours.