Command Line Program to Check if a Number is Palindrome or Not using C Programming language
C Programming Language Command Line Arguments (Article) Command Line Arguments (Program)
847Program:
#include int main(int argc, char *argv[]) { int num, reverse_num=0,remainder,temp; num = atol(argv[1]); temp=num; while(temp!=0) { remainder=temp%10; reverse_num=reverse_num*10+remainder; temp/=10; } if(reverse_num==num) printf("%d is a palindrome number",num); else printf("%d is not a palindrome number",num); return 0; }
Output:
11 11 is a palindrome number
121 121 is a palindrome number
Explanation:
Program without command line arguments
// program by atnyla coder #include void main() { int number, temp, remainder; int sum = 0; printf("Enter a number to check for palindrome. "); scanf("%d", &number); temp = number; while(temp != 0) { remainder = temp % 10; sum = sum*10 + remainder; temp = temp / 10; } if(sum == number) { printf("Number is palindrome"); } else{ printf("Number is not palindrome"); } }
Palindrome or not using a recursive approach
#include int is_Palindrome(int ); int n; int main() { int palindrome; printf("\n\nEnter a number : "); scanf("%d", &n); palindrome = is_Palindrome(n); if(palindrome == 1) printf("\n%d is palindrome\n", n); else printf("\n%d is not palindrome\n", n); return 0; } int is_Palindrome(int aj) { static int sum = 0; if(aj != 0) { sum = sum *10 + aj%10; is_Palindrome(aj/10); // recursive call } else if(sum == n) return 1; else return 0; }
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.