Wednesday, 11 February 2015

Palindrome In c using strcpy

#include
#include

void main()
{
char a[100], b[100];
d:
printf("Enter the string to check if it is a palindrome\n");
gets(a);

strcpy(b,a);
strrev(b);

if( strcmp(a,b) == 0 )
{
printf("Entered string is a palindrome.\n");
}
else
{
printf("Entered string is not a palindrome.\n");
}

}

C Program to Access Elements of an Array Using Pointer in Ascending Order

#include
#include
void main()
{

int x[size], *p, *q, *r, temp,size;
clrscr();
        printf("Number of elements to be entered:");
        scanf("%d",&size);
p=x;
for(q=p; q
{
printf("\nEnter value:");
scanf("%d", q);
}
printf("\n\nkush\n");
printf("\n\nPrinting the elements in asceding order.......\n");
for(q=p; q
{
for(r=q+1; r
{
if(*q>*r)
{
temp=*q;
*q=*r;
*r=temp;
}
}
}
for(q=p; q
{
printf("%d ", *q);
}
getch();
}

Access Elements of an Array Using Pointer Using C

#include
#include
int main()
{

int i, n;
int *a;

printf("Number of elements to be entered:");
scanf("%d",&n);

a = (int*)calloc(n, sizeof(int));
printf("Enter %d numbers:\n",n);
for( i=0 ; i < n ; i++ )
{
scanf("%d",&a[i]);
}

printf("The numbers entered are: ");
for( i=0 ; i < n ; i++ )
    {
printf("%d ",a[i]);
}
return(0);
}

Saturday, 31 January 2015

JAVA program to find out ECHO Server using socket.

//  File name = ConServer.java

import java.net.*;
import java.io.*;
public class ConServer
{
    public static void main(String[] dha)
    {
        ServerSocket s=null;
        try
        {
            s=new ServerSocket(12345);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }       
        while(true)
        {
            try
            { 
          System.out.println("Wllcom To SERVER .......");          
                Socket s1=s.accept();                       
                System.out.println("Enter Your Message For Client ...............");           
                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                OutputStream out=s1.getOutputStream();               
                BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(out));           
                String str;           
                System.out.println("Enter exit++ to stop");                       
                str=br.readLine();
                while(str!=null)
                {
                    if(str.equals("exit++"))
                        break;
                    bw.write(str);
                    bw.newLine();
                    System.out.println("Read: "+str);               
                    str=br.readLine();                               
                }                      
                br.close();
                bw.close();
                s1.close();
            }
            catch(IOException e)
            {
                e.printStackTrace();
            }       
        }
    }   
}

***********************************************************************

 // File Name = ConClient .java

import java.io.*;
import java.net.*;   
public class ConClient
{
    public static void main(String[] dha)
    {
        try
        {
            Socket s1=new Socket("127.0.0.1",12345);
            System.out.println("Wllcom To Client .......");
            System.out.println(" Message Is  .......");        
            InputStream is=s1.getInputStream();    
            BufferedReader br=new BufferedReader(new InputStreamReader(is));
            int i;
            while((i=br.read())!=-1)
            {               
                System.out.print((char)i);                                         
            }
                br.close();
                s1.close();        
    }//try over
        catch(IOException e)
        {           e.printStackTrace();
            System.out.println("Conncection Problem");
        }
    }// main over
  
}// class over



*******************************************************************************
******************** OUTPUT  ********************

ConServer.java



ConClient .java



***************************************************************************

How To Run Server-Client Program                       

***************************************************************************

Step 1 > javac ConServer.java
//compile file

Step 2 > start
//open new terminal

Step 3 > java ConServer

Step 4 >ConClient .java
//compile file In new terminal

Step 5 > java ConClient



Monday, 19 January 2015

Write JAVA Program to print string length using extended thread.

File Name = exteded_thread .java


import java.util.Scanner;
class demo1 extends Thread
{
   Thread t;
   String threadName,s;
   demo1(String name)
   {
       Scanner in = new Scanner(System.in);
       threadName = name;
       System.out.println("Creating Thread......");
       try
        {  
            Thread.sleep(1000);
        }
        catch(InterruptedException e)
        {
            System.out.println("Erroe is --> "+e);
        }
   }
   public void run()
   {
      System.out.println("Running Thread......");
      try
      {     Thread.sleep(1000);
            System.out.println("length Of String Is -->"+s.length());
            Thread.sleep(1000);
      }
      catch(InterruptedException e)
        {
            System.out.println("Erroe is --> "+e);
        }
     System.out.println("Thread Is exiting.");
   }
   public void start ()
   {
      if (t == null)
      {
         t = new Thread (this, threadName);
         t.start ();
      }
   }
}
public class exteded_thread
{  
    public static void main(String args[])
     {
      String s="Wellcome";
      demo1 T1 = new demo1(s);
      T1.start();
     }
}

Write JAVA Program to print 1 to 10 using thread and synchronization.

Write JAVA Program to print 1 to 10 using thread without synchronization.