Tags » C Program

C Program to check if a String Palindrome or not

C Program to check if a String Palindrome or not . Compiled in Dev C++

#include<stdio.h>
#include<string.h>
#include<conio.h>
void reverse_string(char [],char []);
int compare_string(char * , char *);
main()
{
        char a,b;
        int isPalindrome;
        printf("\n Program to Find if a String Palindrome or not Using Pointer\n");
        printf("\n-----------------------------------------------------------------\n\n\n");
        printf("Enter Text : ");
        gets(a);
        strlwr(a);
        reverse_string(a,b);

        isPalindrome=compare_string(a,b);

        if(isPalindrom==1)
        printf("\nString is Palindrome");
        else
        printf("\nString is not Palindrome");

        getch();
        }

 int compare_string(char *first , char *second)
     {
       while(*first!='\0')
       {
           if(*first==*second)
              {
                  first++;
                  second++;
               }
                else
              {
               return 0;
              }

       }

       return 1;

     }

 void reverse_string(char a[],char b[])

     {
          int i,length,n,k=0;
          char *j;
          n=strlen(a);
          for(i=n-1;i>=0;i--)
          {
             j=&a[i];

             b[k]=*j;

             k++;

          }

          b[k]='\0';   

     }

Output

WBUT Assignment

C program to Copy String using Pointer

C program to Copy String using Pointer . compiled in DEV C++


#include<stdio.h>
#include<string.h>
#include<conio.h>
void copy_string(char [],char []);
main()
{
        char a,b;
        int result;
        printf("\n Program to Copy String Using Pointer\n");
        printf("\n--------------------------------------------------------\n\n\n");
        printf("Enter Text : ");                                                   
        gets(a);
        
        copy_string(a,b);
        
        printf("\nSource String %s",a);
        printf("\n\nCopied String %s",b);
       
        getch();
        }
        
        
        
        
   void copy_string(char a[],char b[])
     {
       int i,k=0;
       char *p;
       for(i=0;i<strlen(a);i++)
       {
              p=&a[i];
              b[i]=*p;
             
               
       }
         b[i]='\0'; 
      } 


Output

WBUT Assignment

C program to Compare two String using Pointer

C program to Compare two String using Pointer . compiled in DEV C++

#include<stdio.h>
#include<string.h>
#include<conio.h>
int compare_string(char * , char *);
main()
{
        char a,b;
        int result;
        printf("\n Program to Compare Two String Using Pointer\n");
        printf("\n--------------------------------------------------------\n\n\n");
        printf("First Text : ");
        gets(a);
        printf("\nSecond Text : ");
        gets(b);
        result=compare_string(a,b);
        if(result==1)
        printf("\nString are Same");
        else
        printf("\nString are not Same");
        getch();
        }

   int compare_string(char *first , char *second)
     {
       while(*first!='\0')
       {
           if(*first==*second)
              {
                  first++;
                  second++;
               }
                else
              {
               return 0;
              }

       }

       return 1;

     }

 Output

WBUT Assignment

C program to Concat String using pointer

C program to Concat String using Pointer  . compiled in DEV C++

#include<stdio.h>
#include<string.h>
#include<conio.h>
void concat_string(char a[],char *b);
main()
{
char a,b;
printf("\n Program to Concat String Using Pointer\n");
printf("\n--------------------------------------------------------\n\n\n");
printf("First Text : ");
gets(a);
printf("\nSecond Text : ");
gets(b);
concat_string(a,b);
printf("\nNew text : %s",a);

getch();
}

void concat_string(char a[],char *b)
{
int length=0;
length=strlen(a);

while(*b!='\0')
{
a=*b;

b++;
length++;

}

a='\0';

}
… 6 more words
WBUT Assignment

C Program to Reverse a String Using Pointers

C program to Reverse a string using Pointer . compiled in DEV C++

#include<stdio.h>
#include<string.h>
#include<conio.h>
void reverse_string(char [],char []);
main()
{
        char a,b;
        printf("\n Program to Reverse a String Using Pointer\n");
        printf("\n--------------------------------------------------------\n\n\n");
        printf("Enter Text : ");                                                   
        gets(a);
        reverse_string(a,b);
        printf("\noriginal text %s",a);
        printf("\noreverse text %s",b);
        
        getch();
        }
        
        
        
        
        
   void reverse_string(char a[],char b[])
     {
          int i,length,n,k=0;
          char *j;
          n=strlen(a);
          
          for(i=n-1;i>=0;i--)
          {
             j=&a[i];
             
             b[k]=*j;
             
             k++;
                           
          }
          
          b[k]='\0';   
          
          
     } 

Output

WBUT Assignment

C Program to find length of a String Using Pointers

C program to find the length of a string using Pointer compiled in DEV C++

#include<stdio.h>
#include<string.h>
#include<conio.h>
int string_length(char *);
main()
{
        char a;
        printf("\n Program to find Length of a String Using Pointer\n");
        printf("\n--------------------------------------------------------\n\n\n");
        printf("Enter Text : ");
        gets(a);
        printf("\nString Length %d",string_length(a));
        
        getch();
        }
        
        
        
   int string_length(char *a)
     {
          int count=0;
            while(*a!='')
            {
                           count++;
                           a++;
                           }
                           
                           return count;
          
     }




Output

WBUT Assignment

C++ program to convert Decimal to Binary

C++ Program to Convert Decimal to Binary

It is one the project from Martyr2′s Mega Project List.

Afters 3 days of work I finally worked out an easy to understand and short code for converting Decimal to Binary. 126 more words