A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Palindromic Number in C page! Here, you'll find the source code for this program as well as a description of how the program works.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void palindromic_number(int number)
{
int temp = number, reversed_number = 0;
while (temp > 0)
{
reversed_number = (reversed_number * 10) + (temp % 10);
temp = (int)(temp / 10);
}
if (number < 0)
{
printf("Usage: please input a non-negative integer");
exit(1);
}
else
{
if (reversed_number == number)
{
printf("true");
}
else
{
printf("false");
}
}
}
int is_int(char **argv)
{
int j = 0;
while (isdigit(argv[1][j]))
++j;
if (strlen(argv[1]) != j || j == 0)
{
return 1;
}
else
{
return 0;
}
}
int main(int argc, char **argv)
{
if (argc != 2 || is_int(argv))
{
printf("Usage: please input a non-negative integer");
return 1;
}
palindromic_number(atoi(argv[1]));
return 0;
}
Palindromic Number in C was written by:
If you see anything you'd like to change or update, please consider contributing.
Note: The solution shown above is the current solution in the Sample Programs repository as of Mar 30 2023 15:49:43. The solution was first committed on Nov 01 2021 09:31:02. As a result, documentation below may be outdated.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.