C Program For Palindrome – Check Whether A String Is Palindrome Or Not

C Program For Palindrome String – What is Palindrome? A palindrome is a sequence of characters which reads the same backward as forward. A palindrome could be a word, phrase, number, or other sequences of characters. such as madam or racecar.

 

Palindrome Word Examples:

Madam, Racecar, Radar, Etc.

C Program For Palindrome

If you are looking for a palindrome string in C program, this article will help you to learn how to write palindrome program in C language. Just go through this C program for palindrome to check whether a string is palindrome or not. After going through this C programming tutorial, you will be able to write a  C palindrome program.

C Programming Tutorials

C Program For Palindrome Numbers

C Program To Reverse a String with Using Function

C Program To Reverse a String without Using Function

C Program To Reverse a String Using Recursion

C Program To Reverse a String Using Pointers

C Program For Palindrome String

Learn how to write a  Palindrome program in C language. Writing a C program to check whether a string is a palindrome or not can be done using various techniques, but here in this program, we show how to write palindrome program in a proper way.

This is the eighth C programming example in the series, it helps newbies, students and B.Tech graduates in enhancing C programming and land on their dream job. All the best guys in learning c programming with coding compiler website. Happy Learning.

C Program For Palindrome Source Code

Copy paste the below source code or write your own logic into C compilers and run the program to see the result.

#include <stdio.h> 

#include <string.h> 

int main()

{ 

//Variables declaration

   char string1[20]; 

   int i, length; 

   int flag = 0; 

//Reading a string from user

   printf("Enter a string:"); 

   scanf("%s", string1); 

   length = strlen(string1); 

//checking whether a string is palindrome or not

   for(i=0;i < length ;i++)

   { 

      if(string1[i] != string1[length-i-1])

      { flag = 1; break; } 

   } 

   if (flag) 

   {

      printf("%s is not a palindrome", string1); 

   } 

   else 

  { 

     printf("%s is a palindrome", string1); 

  }

   return 0; 

}

C PROGRAM FOR PALINDROME OUTPUT

After you compile and run the above program, your C compiler asks you to enter a string to check whether entered string is palindrome or not. After you enter a string, the programming logic will check and show result like below expected output.

Example-1

Enter a string:

Radar

Radar is a palindrome

Example-2

Enter a string:

King

King is not a palindrome

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program For Prime Numbers – Check  a Number is Prime or Not

C Program To Reverse a String with Using Function

C Program to Reverse a String without Using Function

C Program to Reverse a Sting Using Recursion

C Program For Palindrome – Check Whether A Number Is Palindrome Or Not

C Program For Palindrome – What is Palindrome? A palindrome is a sequence of characters which reads the same backward as forward. A palindrome could be a word, phrase, number, or other sequences of characters. such as madam or racecar.

Palindrome Number Examples:

1001, 2552, 32423, 959, Etc.

Palindrome Word Examples:

Madam, Racecar, Etc.

C Program For Palindrome

If you are looking for a palindrome in C program, this article will help you to learn how to write palindrome program in C language. Just go through this C program for palindrome to check whether a number is palindrome or not. After going through this C programming tutorial, you will be able to write a  C palindrome program.

C Programming Tutorials

C Program For Palindrome String

C Program To Reverse a String with Using Function

C Program To Reverse a String without Using Function

C Program To Reverse a String Using Recursion

C Program To Reverse a String Using Pointers

C Program For Palindrome Numbers

Learn how to write a  Palindrome program in C language. Writing a C program to check whether a number is a palindrome or not can be done using various techniques, but here in this program, we show how to write palindrome program in a proper way.

This is the seventh C programming example in the series, it helps newbies, students and B.Tech graduates in enhancing C programming and land on their dream job. All the best guys in learning c programming with coding compiler website. Happy Learning.

C Program For Palindrome Source Code

Copy paste the below source code or write your own logic into C compilers and run the program to see the result.

/* C PROGRAM FOR PALINDROME - PALINDROME.C */

#include <stdio.h>
int main()
{

//Variables declaration

 int n, reversedInteger = 0, remainder, originalInteger;

//Taking input number from user

printf("Enter a number: ");
 scanf("%d", &n);

originalInteger = n;

// reversed integer is stored in "reversedInteger" variable
 
 while( n!=0 )
 {
 remainder = n%10;
 reversedInteger = reversedInteger*10 + remainder;
 n /= 10;
 }

// palindrome logic
// if orignalInteger and reversedInteger are equal
// then it is a palindrome

 if (originalInteger == reversedInteger)
 printf(" Entered Number %d is a Palindrome.", originalInteger);
 else
 printf(" Entered Number %d is Not a Palindrome.", originalInteger);
 
 return 0;
}

C PROGRAM For Palindrome OUTPUT

After you compile and run the above program, your C compiler asks you to enter a number to check whether a number is palindrome or not. After you enter a number, the programming logic will check and show result like below expected output.

Enter a number:

1001

Entered Number 1001 is a Palindrome.

 

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program For Prime Numbers – Check  a Number is Prime or Not

C Program To Reverse a String with Using Function

C Program to Reverse a String without Using Function

C Program to Reverse a Sting Using Recursion

C Program To Reverse a String Using Pointers

C Program To Reverse a String Using Pointers – If you are looking for a program for reversing a string in C program, this article will help you to learn how to reverse a string in C using pointers. Just go through this reverse string tutorial you will be able to write a  C program to reverse a string.

C Programming Tutorials

CodingCompiler.com presenting series of C programming tutorials for beginners, experienced to advanced learners. These programming tutorials help C learners, students, B.Tech graduates to enhance their C programming skills and hands-on experience.

C Program To Reverse a String with Using Function

C Program To Reverse a String without Using Function

C Program To Reverse a String Using Recursion

This is the sixth C programming example in the series, it helps newbies in enhancing C programming and land on their dream job. All the best guys in learning c programming with coding compiler website.

C Program to Reverse a String Using Pointers

Learn how to reverse a string in C programming in this tutorial. Reversing a string in C programming language can be done using various techniques, but here in this program, we show how to reverse a string using pointers.

C Program To Reverse a String Source Code

Copy paste the below source code or write your own logic into C compilers and run the program to see the result.

/* C PROGRAM TO REVERSE a STRING - REVERSESTRINGRECURSION.C */

#include<stdio.h>
 
int string_length(char*); //Pointers
void reverse(char*);
 
main() 
{
   char string[100];
 
   printf("Enter a string\n");
   gets(string);  //Input taking from user
 
   reverse(string);
 
   printf("Reverse of entered string is \"%s\".\n", string);
 
   return 0;
}
//Pointers Logic to reverse a string 
void reverse(char *string) 
{
   int length, c;
   char *begin, *end, temp;
 
   length = string_length(string);
   begin  = string;
   end    = string;
 
   for (c = 0; c < length - 1; c++)
      end++;
 
   for (c = 0; c < length/2; c++)
   {        
      temp   = *end;
      *end   = *begin;
      *begin = temp;
 
      begin++;
      end--;
   }
}
 
int string_length(char *pointer)
{
   int c = 0;
 
   while( *(pointer + c) != '\0' )
      c++;
 
   return c;
}

C Program To Reverse a String Output

After you compile and run the above program, your C compiler asks you to enter a string to reverse. After you enter a string, the recursive function will reverse the string and show output like below expected output.

Enter a string

programming

Reverse of entered string is

gnimmargorp

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program For Prime Numbers – Check  a Number is Prime or Not

C Program To Reverse a String with Using Function

C Program to Reverse a String without Using Function

C Program to Reverse a Sting Using Recursion

C Program to Reverse a String Using Recursion

C Program to Reverse a Sting Using Recursion –  If you are looking for reversing a string in C program, this article will help you to guide how to reverse a string in C using recursion. Just go through this reverse string tutorial you will be able to write a  C program to reverse a string.

C Programming Tutorials

CodingCompiler.com presenting series of C programming tutorials for beginners, experienced to advanced learners. These programming tutorials help C learners, students, B.Tech graduates to enhance their C programming skills and hands-on experience.

C Program To Reverse a String with Using Function

C Program To Reverse a String without Using Function

C Program To Reverse a String Using Pointers

This is the sixth C programming example in the series, it helps newbies in enhancing C programming and land on their dream job. All the best guys in learning c programming with coding compiler website.

C Program to Reverse a String Using Recursion

Learn how to reverse a string in C programming in this tutorial. Reversing a string in C programming language can be done using various techniques, but here in this program, we show how to reverse a string using recursion.

C Program To Reverse a String Source Code

Copy paste the below source code or write your own logic into C compilers and run the program to see the result.

/* C PROGRAM TO REVERSE a STRING - REVERSESTRINGRECURSION.C */

#include <stdio.h>
#include <string.h>
 
void reverse(char*, int, int); //Method
 
int main()
{
   char a[100];  //Variables
 
   gets(a);
 
   reverse(a, 0, strlen(a)-1);
 
   printf("%s\n",a);
 
   return 0;
}
 // Logic for reversing a string
void reverse(char *x, int begin, int end) //Recursion
{
   char c;
 
   if (begin >= end)
      return;
 
   c          = *(x+begin);
   *(x+begin) = *(x+end);
   *(x+end)   = c;
 
   reverse(x, ++begin, --end);
}

C Program To Reverse a String Output

After you compile and run the above program, your C compiler asks you to enter a string to reverse. After you enter a string, recursive function will reverse the string and show output like below expected output.

Input a string

programming

Reverse of entered string is

gnimmargorp

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program For Prime Numbers – Check  a Number is Prime or Not

C Program To Reverse a String with Using Function

C Program to Reverse a String without Using Function

C Program to Reverse a String without Using Function

C Program to Reverse a String without Using Function – If you are searching for reversing a string in C program, this article will help you to learn how to reverse a string in C without using strrev() function. Just go through this reverse string tutorial you will be able to write a  C program to reverse a string.

C Programming Tutorials

CodingCompiler.com publishing series of C programming tutorials for beginners to advanced learners. These programming tutorials help C learners, students, B.Tech graduates to enhance their C programming skills and hands-on experience on coding.

C Program To Reverse a String with Using Function

C Program To Reverse a String Using Pointers

C Program To Reverse a Sting Using Recursion

This is the fifth C programming example in the series, it helps newbies in learning C programming and land on their dream job. All the best guys in learning c programming with coding compiler website.

C Program To Reverse a String Without Using Function

Learn how to reverse a string in C programming in this tutorial. Reversing a string in C programming language can be done using various techniques, but here in this program, we show without using strrev() function to reverse a string.

C Program To Reverse a String Source Code

Copy paste the below source code or write your own logic into C compilers and run the program to see the result.

/* C PROGRAM TO REVERSE a STRING - REVERSESTRING.C */

#include <stdio.h>
#include <string.h>
 
int main()
{
   char s[100], r[100]; //variables declaration
   int n, c, d;         //Integer variables
 
   printf("Input a string\n");
   gets(s);             //Getting input string from user
 
   n = strlen(s);     
   //Logic for reversing a string without using function
   for (c = n - 1, d = 0; c >= 0; c--, d++)
      r[d] = s[c];
 
   r[d] = '\0';
 
   printf("%s\n", r);
 
   return 0;
}

C Program To Reverse a String Output

After you compile and run the above program, your C compiler asks you to enter a string to reverse. After you enter a string, programming llogic will reverse the string and show output like below expected output.

Input a string

programming

Reverse of entered string is

gnimmargorp

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program For Prime Numbers – Check  a Number is Prime or Not

C Program To Reverse a String with Using Function

C Program To Reverse a String Using STRREV Function

C Program To Reverse a String – If you are looking for reversing a string in C program, this article will guide you to learn how to reverse a string in C. Just go through this reverse string tutorial you will be able to write a program to reverse sting.

CodingCompiler.com publishing series of easy to complex C programs for beginners, students, B.Tech graduates to enhance their C programming skills and hands-on experience on coding. This is the fourth C programming example in the series, it helps newbies in reaching their goals in the career. All the best guys in learning c programming with coding compiler blog.

C Program To Reverse a String

Learn how to reverse a string in C programming. Reversing a string in C programming language can be done using various techniques, but here in this program, we used strrev() function to reverse a string.

C Program To Reverse a String without Using Function

C Program To Reverse a String Using Pointers

C Program To Reverse a Sting Using Recursion

C Program To Reverse a String Source Code

Copy paste the below source code or write your own logic into C compilers and run the program to see the result.

/* C PROGRAM TO REVERSE a STRING - REVERSESTRING.C */
#include <stdio.h>
#include <string.h>
 
int main()
{
   char arr[100];
 
   printf("Enter a string to reverse\n");
   gets(arr); //This function will get a string from user
 
   strrev(arr); //This function will reverse a string
 
   printf("Reverse of entered string is \n%s\n",arr);
 
   return 0;
}

C Program To Reverse a String Output

After you compile and run the above program, your C compiler asks you to enter a string to reverse. After you enter a string, strrev() function will reverse the string and show output like below expected output.

Enter a string to reverse programming

programming

Reverse of entered string is

gnimmargorp

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program For Prime Numbers – Check  a Number is Prime or Not

 

C Program For Prime Numbers – Check Whether A Number Is Prime Or Not

C Program For Prime Numbers – If you are looking for finding prime numbers in C program, this article will guide you to learn to check whether a number is prime or not in C. Just go through this C program to find prime number tutorial you will be able to write a program to check prime number in C.

CodingCompiler.com publishing series of C programs for beginners, students, B.Tech graduates to enhance their C programming skills and hands-on experience on coding. This is the third C programming example in the series, it helps newbies in reaching their goals in the career. All the best guys in learning c programming with coding compiler blog.

C Program For Prime Numbers

Check whether a number is prime or not in C in C programming language can be done using various techniques, but here in this program, we used three variables to find prime numbers.

C Program To Find Prime Number Source Code

Copy paste the below C program to find prime number source code or write your own logic into C compilers and run the program to see the result.

Source Code:

/*C PROGRAM FOR PRIME NUMBER - PRIMENUMBERS.C */

#include <stdio.h>
int main()
{
   int n, i, flag = 0; //Variables

   printf("Enter a positive integer: "); 
   scanf("%d",&n); //Reading input from users

  for(i=2; i<=n/2; ++i) // Logic for finding prime number
  {
    
    if(n%i==0)
     {
      flag=1;
      break;
     }
  }

   if (flag==0)
     printf("%d is a prime number.",n);
   else
     printf("%d is not a prime number.",n);
 
 return 0;
}

C Program For Prime Numbers Output

After you compile and run the above program, your C compiler asks you to enter a number to check whether a number is a prime number or not. After you enter a positive integer, then it will show output with the result saying the entered number is prime or not like below expected output.

Enter a positive integer: 29

29 is a prime number.

Related C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program To Swap Two Numbers Using Three Variables

C Program To Swap Two Numbers Using Three Numbers – If you are looking for swapping C program, this article will guide you to lean swapping two numbers in C using 3 variables. Just go through this swapping tutorial you will able write a program to swap two numbers using three variable a,b and c.

We are publishing series of C programs for beginners, students, B.Tech graduates to enhance their C programming skills and hands-on experience on coding. This is the second C programming example in the series, it helps newbies in reaching their goals in the career. All the best guys in learning c programming with coding compiler blog.

C Program To Swap Three Numbers

Swapping in C programming language can be done using various techniques, like using two variables, three variables, and functions, but here in this swapping program, we used three variables to perform swap two numbers in C.

C Program To Swap Three Numbers Source Code

Copy paste the below source code or write your own logic into C compilers and run the program to see the result.

/* Swapping 2 Using Three Variables In C - SWAPTWONUMBERS.C */

#include<stdio.h>
#include<conio.h>
void main()
{
    int a, b, c ;
    clrscr() ;
    printf("Enter two numbers : ") ;
    scanf("%d %d", &a, &b) ;
    printf("\nBefore swapping : \n\n") ;
    printf("a = %d \t b = %d", a, b) ;

    /* Swapping Two Numbers Logic */
    c = a ;
    a = b ;
    b = c ;
    printf("\n\nAfter swapping : \n\n") ;
    printf("a = %d \t b = %d", a, b) ;
    getch();
}

C Program To Swap Two Numbers Output

After you compile and run the above program, your C compiler asks you to enter two numbers to swap, then it will show output before swapping and after swapping two numbers like below expected output.

Enter two numbers: 10 20

Before swapping :
a = 10 b = 20

After swapping :
a = 20 b = 10

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers – If you are looking for swapping program in C language, this article will help you to lean swapping two numbers in C. Just go through this blog post you will able write a program to swap two numbers using two variable num1 and num2.

We are going to publish series of C programs for beginners, students, B.Tech graduates to enhance their programming skills and hands on experience on coding. So it helps in reaching their goals in career. All the best guys in learning c programming with coding compiler blog.

C Program To Swap Two Numbers

Swapping in C language can be done using various techniques, here in this swapping program we used two variables to perform swap two numbers.

C Program To Swap Two Numbers Source Code

Copy paste the below source code in to c compilers and run the program to see the the result.

/* Swapping Two Numbers Using Two Variables In C - SWAPTWONUMBERS.C */

#include<stdio.h>
#include<conio.h>
void main()
{
    int num1, num2 ;
    clrscr() ;
    printf("Enter two numbers : ") ;
    scanf("%d %d", &num1, &num2) ;
    printf("\nBefore swapping : \n\n") ;
    printf("num1= %d \t num2 = %d", num1, num2) ;

    /* Swapping Two Numbers Logic */
    num1 = num1 + num2 ;
    num2 = num1 - num2 ;
    num1 = num1 - num2 ;
    printf("\n\nAfter swapping : \n\n") ;
    printf("num1 = %d \t num2 = %d", num1, num2) ;
    getch() ;
}

C Program To Swap Two Numbers Output

After you compile and run the above program your C compiler asks you to enter two numbers, then it will show output before swapping and after swapping two numbers like below expected output.

Enter two numbers : 10 20

Before swapping :
num1 = 10 num2 = 20

After swapping :
num1 = 20 num2 = 10

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables