Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE HELP WITH COMPLETE CODE. I will RATE!!!! This is what I have. I am gettin

ID: 3531466 • Letter: P

Question










PLEASE HELP WITH COMPLETE CODE. I will RATE!!!!

This is what I have. I am getting stuck at how to get a compact palindorme.



#include<stdio.h>
#include<math.h>
#define FALSE 0
#define TRUE 1
#define REGULAR 2
#define BOTH 3
#define SPLACE 10

long long int Getinput();
long long int Testpalin(long long int);
long long int Testgreater(long long int);
long long int Testless(long long int);
long long int Testret(long long int, long long int, long long int);
void Printoutput1(long long int, long long int);
void Printoutput2(long long int, long long int, long long int);
void Printoutput(long long int);


int main()
{
long long int number; //declares number which is the intager entered by the user
long long int ansg; //declares ansg which is the closest palindrome that is greater
long long int ansl; //declares ansl which is the closest palindrome which is lesser
long long int anss; //declares anss whach is a value that stores a 1 or 0 based on if the entered number is a palindrome
long long int testret; //declares testret which is a 1 2 or 3 based on what print statement properly displayes the output
number = Getinput();
ansg = Testgreater(number);
ansl = Testless(number);
anss = Testpalin(number);
testret = Testret(ansg, ansl, number);

if(anss == TRUE) //sends to the print statement indicating that the entered number is a palindrome
{
Printoutput(number);
}
if(testret == TRUE && anss != TRUE) //sends to a print statement indicating that the greater palindrome is closer
{
Printoutput1(number, ansg);
}
if(testret == REGULAR && anss != TRUE) //sends to a print statement indicating that the lesser palindrome is closer
{
Printoutput1(number, ansl);
}
if(testret == BOTH && anss != TRUE) //sends to the print statement indicating that the entered number is equidistant from the lower and higher palindrome
{
Printoutput2(number, ansg, ansl);
}

return(FALSE);
}


long long int Getinput()
{
long long int number;
do
{
printf(" Enter a non-negative value: ");
scanf("%lld", &number);

if (number < FALSE)
{
printf(" Error! Please enter a non-negative values only! ");
}
}while (number < FALSE);
return(number);
}



long long int Testpalin(long long int number)
{
long long int x;
long long int y;
long long int ct1 = FALSE;
long long int newnum = FALSE;
long long int z;
long long int ans;

z = number;
x = number;


while(x > FALSE) //this loop counts how many place values are in a number
{
x = x / SPLACE;
ct1++;
printf(" x = %lld ", x);
}

while(z > FALSE) //this loop reverses the order of numbers that make up the sent number
{
y = z % SPLACE;
newnum += y * pow(SPLACE, --ct1);
z = z / SPLACE;
printf("z = %lld ", z);
printf(" newnum = %lld ", newnum);
}

ans = (number == newnum) ? TRUE : FALSE;
printf("answer = %lld ", ans);
return(ans);
}


long long int Testgreater(long long int number)
{
long long int x;
do
{
x = Testpalin(number);
if(x == FALSE)
{
number++;
}
}while(x == FALSE);

return(number);
}


long long int Testless(long long int number)
{
long long int x;
do
{
x = Testpalin(number);
if(x == FALSE)
{
number--;
}
}while(x == FALSE);

return(number);
}



long long int Testret(long long int ansg, long long int ansl, long long int number)
{
long long int val;
if((ansg - number) < (number - ansl))
{
val = TRUE;
}
if((ansg - number) > (number - ansl))
{
val = REGULAR;
}
if((ansg - number) == (number - ansl))
{
val = BOTH;
}

return(val);
}



void Printoutput1(long long int number, long long int ans)
{
printf(" Closest palindrome to %lld: %lld ", number, ans);
}



void Printoutput2(long long int number, long long int ansl, long long int ansg)
{
printf(" Closest palindromes to %lld are: %lld, %lld ", number, ansg, ansl);
}



void Printoutput(long long int number)
{
printf(" The value input (%lld) is a palindrome ", number);
}

Explanation / Answer

25 is not a palindrome

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote