The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Sunday, March 18, 2012

Find Palindrome of String


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

char a[20];
int l;

int palin(int num)
{
 if(num>l/2)
  return 1;
 if(a[num] == a[l-num-1])
  return palin(num+1);
 else
  return 0;
}


void main()
{
 clrscr();
 printf("Enter a String : ");
 gets(a);
 l = strlen(a);
 int ret = palin(0);
 if(ret == 1)
  printf("\n Palindrome");
 else
  printf("\n Not Palindrome");
 getch();
}

Thursday, March 8, 2012

Finding Eigenvalue


#include<iostream.h>
//#include<conio.h>
#include<math.h>
#define max 2

class matrix
{
  private :
 int num[max][max];
 int rt1,rt2;
 int egn1[max][1],egn2[max][1];
  public :
 void inp_mat()
 {
  cout<<"\n\n Enter the elements in the matrix";
  for(int i=0;i<max;i++)
  {
   cout<<"\n Enter elements for Row#"<<i+1<<" : ";
   for(int j=0;j<max;j++)
    cin>>num[i][j];
  }
 }
 void fnd_egn()
 {
  int a,b,c,det,quo;
  a = 1;
  b = -(num[0][0]+num[1][1]);
  c = (num[0][0]*num[1][1])-(num[0][1]*num[1][0]);
  cout<<"\n Its' characterristic equation is : "<<a<<"*x*x + "<<b<<"*x +"<<c;
  det = b*b - 4*a*c;
  rt1 = (-b+sqrt(det))/(2*a);
  rt2 = (b+sqrt(det))/(2*a);
  cout<<"\n\n And, the Eigenvalues are : "<<rt1<<" and "<<rt2;
  a = num[0][0] - rt1;
  b = num[0][1];
 quo = a>b?-a/b:-b/a;
  if(quo>0)
  {
   egn1[0][0] = quo;
   egn1[1][0] = 1;
  }
  else
  {
   egn1[1][0] = quo;
   egn1[0][0] = 1;
  }
  cout<<"\n\n The Eigenvector correspoding to Eigenvalue "<<rt1;
  cout<<"\n\n\t\t"<<egn1[0][0]<<"\n\t\t"<<egn1[1][0];
  a = num[0][0] - rt2;
  b = num[0][1];
  quo = a>b?-a/b:-b/a;
  if(quo>0)
  {
   egn2[0][0] = quo;
   egn2[1][0] = 1;
  }
  else
  {
   egn2[1][0] = quo;
   egn2[0][0] = 1;
  }
  cout<<"\n\n The Eigenvector correspoding to Eigenvalue "<<rt2;
  cout<<"\n\n\t\t"<<egn2[0][0]<<"\n\t\t"<<egn2[1][0];
 }
};

int main()
{
 //clrscr();
 matrix mat;
 mat.inp_mat();
 mat.fnd_egn();
// getch();
 return 0;
}