Showing posts with label String. Show all posts
Showing posts with label String. Show all posts

Write a c program to check given string is palindrome number or not.

How to Write a c program to check given string is palindrome number or not.


#include<string.h>
#include<stdio.h>
int main(){
  char *str,*rev;
  int i,j;
  printf("\nEnter a string:");
  scanf("%s",str);
  for(i=strlen(str)-1,j=0;i>=0;i--,j++)
      rev[j]=str[i];
      rev[j]='\0';
  if(strcmp(rev,str))
      printf("\nThe string is not a palindrome");
  else
      printf("\nThe string is a palindrome");
  return 0;
}

C Program String Example

How to write a C Program String Example in C Programming Language ?


Solution For C Program :

C Program String Count Example

How to write a C Program String Count in C Programming Language ?


Solution For C Program :

C Program String Example

How to write a C Program String Example in C Programming Language ?


Solution For C Program :

C Program to Print a String Without Use Semicolon.

How to write a C Program to Print a String Without Use Semicolon in C Programming Language ?


Solution For C Program :

/*C Program to Print a String Without Use Semicolon.*/

#include <stdio.h>
#include <conio.h>
void main()
{
 if(printf("Hello"))
}

C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters

How to write a C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters in C Programming Language ?


Solution For C Program :

/*C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters.*/

/*New line character will be taken as a string terminating character.*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int xstrlen(char *);
void main()
{
char s1[20];
int len;
clrscr();
printf("\nEnter the string:");
gets(s1);
len=xstrlen(s1);
printf("\nlength of the string =%d",len);
getch();
}
int xstrlen(char *s)
    {
    int l=0;
    while(*s)
      {
      l++;
      s++;
      }
    return (l);
    }


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program To Find Length Of String And Concatenate Two Strings

How to write a C Program To Find Length Of String And Concatenate Two Strings in C Programming 

Solution For C Program :

/* C program which read two strings and concatenate the largest string to the smallest string (among the two strings).*/

#include<stdio.h>
#include<string.h>
#include<conio.h>

int leng(char str[20]);
void concat(char str4[20], char str5[20]);
void main()
{
char str1[20],str2[20],str3[20];
int i,j,len,first,second;
clrscr();
printf("Enter the first string:\n");
gets(str1);

printf("Enter the second string:\n");
gets(str2);
first=leng(str1);
second=leng(str2);
printf("\nLength of 1st string= %d",first);
printf("\nLength of 2nd string= %d",second);

if(first<=second)
    {
    concat(str1,str2);
    }
else
    {
    concat(str2,str1);
    }
getch();
}

int leng(char str[20])
    {
    int i=0;
    while(str[i]!='\0')
        {
        i++;
        }
    return(i);
    }

void concat(char str4[20], char str5[20])
    {
    int i=0,j;
    char str6[20];
    while(str4[i]!='\0')
        {
        str6[i]=str4[i];
        i++;
        }
    j=0;
    while(str5[j]!='\0')
        {
        str6[i]=str5[j];
        i++;j++;
        }
    str6[i]='\0';
    printf("\n\nConcanated string= %s",str6);
    }


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not

How to write a C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not in C Programming Language ?


Solution For C Program :

/*C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not.*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,length=0,flag;
char str[10],rev[10];
clrscr();
printf("Enter the string==>");
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
{
length++;
}
printf("\nLength of %s is ==>%d\n",str,length);
length--;
for(i=0;length>=0;i++)
{
 rev[i]=str[length];
 length--;
}
rev[i]='\0';
printf("\nReverse of %s is ==>%s\n",str,rev);

 length++;
for(i=0;rev[i]!='\0';i++)
{
length++;
}
printf("\nLength of %s is ==>%d\n",rev,length);

for(i=0;str[i]!='\0'||rev[i]!='\0';i++)
{
if(str[i]!=rev[i])
    {
    flag=1;
    break;
    }
}
if(flag==1)
printf("\nString is not polyndrom");
else
printf("\nString is polyndrom");
getch();
}

C Program To Print String In Formatted Output Form

How to write a C Program To Print String In Formatted Output Form in C Programming Language ?


Solution For C Program :

/*C Program To Print String In Formatted Output Form.*/

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
int i;
char name[10]="math",a[]="aaaaaaaaaaaaaaa",c='y';
clrscr();
puts(name);
for(i=1;i<5;i++)
    {
    printf("%10.*s\n",i,name);
    }
printf("\n-----------------\n");
for(i=0;i<5;i++)
    {
    printf("%*c\n",i,c);
    }
for(i=5;i>0;i--)
    {
    printf("%*c\n",i,c);
    }
getch();
}


OUTPUT :
math
            m
          ma
        mat
      math

-----------------
y
  y
    y
      y
         y
       y
      y
    y
  y
y



You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable



C Program To Reverse The String Using Pointer

How to write a C Program To Reverse The String Using Pointer in C Programming Language ?


Solution For C Program :

/*C Program To Reverse The String Using Pointer.*/


#include<stdio.h>
#include<conio.h>
void reverse(char *);
void main()
{
clrscr();
  char st[10];
  gets(st);
  printf("reverse=");
  reverse(st);
  printf("\noriginal data=%s",st);
  getch();
}
void reverse(char *s)
{
  char c;
  if (*s==NULL)
  {
     return;
  }
  c=*s;
  s++;
  reverse(s);
  printf("%c",c);
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable