Tuesday, June 22, 2010

Program to Print the number words in a string and Print in a Specified Format

#include"iostream.h"

void main()
{
 char a[100];
 int i=0,j=0,n[10],wn=0,count=0,n1[10] = {0,0,0,0,0,0,0,0,0,0},n2;
 clrscr();
 printf("\n PLEASE END THE STRING BY USING ( . ) SYMBOL TO GET THE CORRECT OUTPUT\n\n   ");
 gets(a);
 while(a[i] != '\0')
 {
  if(a[i] == ' ' || a[i] =='.')
  {
   n[j] = i-wn;
   wn = i+1;
   j++;
   count++;
  }
  i++;
 }

 cout <<"\n NUMBER OF WORDS : "<<"\n";

 for(i=0;i < count;i++)
 {
   n2 = n[i];
   n1[n2]++;
 }

 for(i=1;i < 10;i++)
 {
  cout << "\n NUMBER OF "<<  i <<" LETTER WORD : " <
 }
 getch();
}



INPUT
PLEASE END THE STRING BY USING ( . ) SYMBOL TO GET THE CORRECT OUTPUT
I AM HAPPY.
(END THE STRING WITH . SYMBOL)


OUTPUT WILL BE LIKE THIS
NUMBER OF 1 LETTER WORD 1
NUMBER OF 2 LETTER WORD 1
NUMBER OF 3 LETTER WORD 0
NUMBER OF 4 LETTER WORD 0
NUMBER OF 5LETTER WORD  1
NUMBER OF 6 LETTER WORD 0

Sunday, June 13, 2010

Signs Of Aged World Counting Its Days...!???

A mild earthquake (tremor) has been reported in various parts of Chennai in the early morning on Sunday, June 13, 2010. The tremor lasted for about 15-20 seconds and it was felt in areas including Chintadripet, Thiruvanmiyur, Santhome, Choolaimedu, Koyambedu, Royapettah and Aminjikarai.


After the Earthquake A few mins later all the persons sleeping in Marina Beach were cleared as there is Tsunami warning all over 7 countries in the world. Actually this ia a tremor felt in Chennai and other regions due to 7.7 Earthquake in Nicobar Islands.

Several parts of Sri Lanka experienced tremors following the earthquake, according to the head of the country's Geology and Mines Bureau, D Wijayananda.

Tuesday, June 1, 2010

PALINDROME PROGRAM IN C++ WITH EXPLANATION.. This will be correct logic which everyone expects



 What we have to do is
i)                    Find the length of the string
ii)                   Divide the length of the string by 2. Because from the first element in the array we should go until the predecessor of middle element and then from the last we go until the successor of the middle element Take this as an example
If this is the input string “LIRIL”. Here the middle element is a[3] = ‘R’, to find whether it is palindrome or not we should check as given in the diagram. Then we should compare the last element and with the first element. Like        

1.      We check the last element a[5] and the first element a[1].
2.      We check the second from the first a[2] with the second from the last a[4].
              
                  Middle element need not to be checked because it positions will not be changed if the string is reversed. This the logic behind this program.

If the length of the string is even( EG, 4 OR 8 OR 10) then there will be no middle element as given in the above example.

For eg) for the string “KAIL

                        

void main()
{
 int i,j,n=0,n1,cnt=0;
 char a[20];
 clrscr();
 printf("\n ENTER THE STRING : ");
 cin>>a;

// Here we get calculate the length of the string
 while(a[n]!='\0')
 {
 n =n+1;
 }
// Completes here

// To find the middle value. If the length is a even number it takes the value 0.
 n1 = n/2;
//completes here

/* This loop check the a[i] before n1 with a[j] until before n1. Remember a[i] starts from the first and b[j] starts from the last index */

for(i=0,j=n-1; i < n1 && j  >  n1; i++, j--)
 {
   if(a[i] == a[j])
    cnt++;
  else
  {
   printf("\n THE STRING IS NOT A PALINDROME");
   break;
  }
 }
 if(cnt == n1)
  printf("\n THE STRING IS A PALINDROME");
getch();
}