C++ ~ myTechpartner Join Me On Facebook
Join Me On Facebook

Blogroll

C++


images.jpg

Easy To Study
                                                                 


1) Program to check whether a given string is palindrome or not
 
      #include<iostream.h>
      #include<string.h>
      #include<conio.h>
      int checkPalindrom(char a[])
       {
          int i,j,l;
          l=streln(a);
          for(i=0,i=l-1;i<j;i++,j--)
            if(a[i]!=a[j])
            return1;
        }
      void main()
       {
         clrscr();
         char a[100];
         cout<<"enter a string : ";
         cin>>a;
         if(checkPalindrom(a)!=0)
            cout<<"the string entered palindrome";
         else
            cout<<"the string entered not palindrome";
         getch();
      }

OUTPUT:
    enter a string : malayalam
    the string entered palindrome


2) Program to check whether a given number is prime or not

      #include<iostream.h>
      #include<conio.h>
      #include<process.h>
      #include<math.h>
      void main()
       {
          clrscr();
          int a,i,j,f=0;
          cout<<"Enter a number: ";
          cin>>a;
          if(a==1)
           {
              cout<<"The number entered is neither prime nor composite";
              getch();
              exit(0);
            }
          for(i=2;i<=sqrt(a);i++)
            {
              j=a%i;
              if(j==0)
                {
                   f=1;
                   break;
                }
             }
          if(f!=1)
              cout<<"The number entered is prime:";
         else
              cout<<"The number entered not prime: ";
         getch();
    }

OUTPUT
     Enter a number :3
     The number entered is not prime
 

























1 comment:

  1. Akhil A Chandran28 July 2013 at 18:08

    This site was very simple and its easy to understand the contents. I request you to Blogger that, please add some more programs (in c++). I hope that you will take this comment as the right sense.
    Thank you and Good luck for the site.
    Akhil A.C

    ReplyDelete

 

Contributors

Online Marketing

Do you Like this Article?

rss twitter facebook