Thursday, 19 November 2015

c program for prime numbers from 1 to 100

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

void main()
{
 int num,n,div,p;
 printf("Enter any number: ");
 scanf("%d", &num);
 for(n=2; n<=num; n++)
 {
  for(div=2; div
  {
   if(n%div==0)
   {
     p=0;
     break;
   }
   p=1;
  }
  if(p)
    printf("\t%d",n);
 }
 getch();
 return 0;
}

Friday, 24 April 2015

How to Show Hidden Files and Folders



STEP 1 : - START  CMD

STEP 2 :- Then WRITE THIS CODE ....

attrib -s -h -r /s /d  g:\*.*

NOTE  :-

REPLACE  G  WITH YOUR USB DRIVE NAME .....




Monday, 30 March 2015

Multiple Matrix multiplication in c

#include
int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];

printf("Enter the first matrix number of rows and columns \n");
scanf("%d%d", &m, &n);
printf("Enter elements\n");

for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);

printf("Enter the second matrix number of rows and columns\n");
scanf("%d%d", &p, &q);
if (n != p) printf("Not valid Matrix \n");
else {
printf("Enter elements \n");
for (c = 0; c < p; c++)
for (d = 0; d < q; d++)
scanf("%d", &second[c][d]);
for (c = 0; c < m; c++)
{
for (d = 0; d < q; d++)
{
for (k = 0; k < p; k++)
{
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum; sum = 0;
}
}
printf("Result Is :-\n");
for (c = 0; c < m; c++)
{
for (d = 0; d < q; d++)
printf("%d\t", multiply[c][d]);
printf("\n");
}
}
return 0;}

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.


Write JAVA thread Program to find length of String.

File Name=RunnableDemo

import java.util.Scanner;
class RunnableDemo1 implements Runnable
{
   private Thread t;
   private String threadName;
   String s;
   RunnableDemo1(String name)
   {
   Scanner in = new Scanner(System.in);
   threadName = name;
   System.out.println("Enter String ");
   s = in.nextLine();
   }

  public void run()
{
        try {
                Thread.sleep(5000);
                System.out.println("length Of Thread " +  s.length());
            }
            catch (InterruptedException ex)
            {
               System.out.println("Exception "+ex');
            }
   }

   public void start ()
   {
         t = new Thread (this, threadName);
         t.start ();
   }
}

public class RunnableDemo
{
   public static void main(String args[])
  {
      RunnableDemo1 R1 = new RunnableDemo1("Thread-1");
      R1.start();
   }
}

    

JAVA Program to implement Simple Thread program

File name = RunnableDemo.java 


class RunnableDemo1 implements Runnable
{
   private Thread t;
   private String threadName;
   RunnableDemo1(String name)
   {
   threadName = name;
   System.out.println("Thread Is Start"+  threadName );
   }
  public void run()
  {
        try {
                Thread.sleep(5000);
                System.out.println("Thread Is Running " +  threadName );
                Thread.sleep(5000);
                System.out.println("length Of Thread " +  threadName.length());
            }
            catch (InterruptedException ex)
            {
                System.out.println("Exception is  "+ex);
            }
        System.out.println("Thread Is Exit " +  threadName );
   }
   public void start ()
   {
         t = new Thread (this, threadName);
         t.start ();
System.out.println("Thread Is Create "+  threadName );
   }
}

public class RunnableDemo
{
   public static void main(String args[])
 {
      RunnableDemo1 R1 = new RunnableDemo1("Thread-1");
      R1.start();
   }  
}


Tuesday, 14 October 2014

C Program to crate lexical analyzer which will do space removal.

#include
#include
#include
#include

int key = 0;
char expr[100];
char cont[][20]={"CONTROLS","for","do","while","NULL",};
char cond[][20]={"CONDITION","if","then","NULL"};
char oprt[][20]={"OPERATOR","+","-","*","/","%","<","<=",">",">=","=","(",")","NULL"};
char branch[][20]={"BRANCHING","goto","jump" ,"NULL"};

void checking(char[],char[][20]);

void main()
{
int i,j,l,k,m,n;
char sbexpr[50],txt[3];
clrscr();
cout<<"Enter the expression:";
gets(expr);
for(i=0;expr[i]!=NULL;i++)
{
key=0;
for(j=i,k=0;expr[j]!=32 && expr[j]!=NULL;i++,j++,k++)
sbexpr[k]=expr[j];
sbexpr[k]=NULL;

if(key==0) checking(sbexpr,cond);

if(key==0) checking(sbexpr,cont);

if(key==0) checking(sbexpr,branch);

if(key==0)
{
for(m=0;sbexpr[m]!=NULL;m++)
{
key=0;
txt[0]= sbexpr[m];
txt[1] = NULL;

if(key==0) checking(txt,oprt);
if((key==0) || ((sbexpr[m]>=97 && sbexpr[m]<=122) || (sbexpr[m]>=65 && sbexpr[m]<=90)))
{
cout<<"\n"<"<<"Identifier\n";
key = 1;
}
}
}
if(key == 0)
{
cout<<"\n"<"<<"Address\n";
key = 1;
}
}

getch();
}


void checking (char expr[],char check[][20])
{
for(int i=1;strcmp(check[i],"NULL")!=0;i++)
{
if(strcmp(expr,check[i])==0)
{
cout<"<key = 1;
}
}
}

C Program to implement Recursive Deceptive Parsing

#include
#include
#include
void main()
{
int i,j,k;
char a[20],b[20],c[20],m,n[10],o[10];
clrscr();
printf("Enter a recursive string:");
gets(a);
if(a[0]==a[3]) {
m=a[0];
printf("%c\n",m);
}
else {
printf("Entered string is not recursive");
}
j=0;
for(i=4;a[i]!=NULL;i++) {
if(a[i]!='/') {
b[j++]=a[i];
printf("%c",b[j]);
}
else {
goto a1;
}
}
a1:
b[j]='\0';
j=0;
for(i=i+1;a[i]!=NULL;i++) {
c[j]=a[i];
j++;
}
c[j]='\0';
n[0]=m;
n[1]='-';
n[2]='>';
j=3;
for(i=0;c[i]!=NULL;i++) {
n[j]=c[i];
j++;
}
n[j++]=m;
n[j++]='`';
n[j++]='\0';
printf("\n\nOutput string1 is:");
puts(n);
o[0]=m;
o[1]='-';
o[2]='>';
j=3;
for(i=0;b[i]!=NULL;i++)
{
o[j]=b[i];
j++;
}
puts(b);
o[j++]=m;
o[j++]='`';
o[j++]='/';
o[j++]='$';
o[j++]='\0';
printf("\n\nOutput string is:");
puts(o);
getch();
}

C Program to implement Recursive Descentive Parsing.

#include
#include
#include
#include
#include
char ip_sym[15],ip_ptr=0,op[50],tmp[50];
void e_prime();
void e();
void t_prime();
void t();
void f();
void advance();
int n=0;
void e(){
            strcpy(op,"TE'");
 printf("E=%-25s",op);
 printf("E->TE'\n");
            t();
 e_prime();
}
void e_prime(){
int i,n=0,l;
for(i=0;i<=strlen(op);i++)
            if(op[i]!='e')
 tmp[n++]=op[i];
strcpy(op,tmp);
l=strlen(op);
for(n=0;n < l && op[n]!='E';n++);
if(ip_sym[ip_ptr]=='+')            {
                         i=n+2;
 do {
                                    op[i+2]=op[i];
 I++;
                        }while(i<=l);
                         op[n++]='+';
                        op[n++]='T';
                        op[n++]='E';
                        op[n++]=39;
                        printf("E=%-25s",op);
                        printf("E'->+TE'\n");
                        advance();
                        t();
e_prime();
            }
else{
                        op[n]='e';
                        for(i=n+1;i<=strlen(op);i++)
                        op[i]=op[i+1];
                        printf("E=%-25s",op);
                        printf("E'->e");
}
}
void t(){
 int i,n=0,l;
            for(i=0;i<=strlen(op);i++)
            if(op[i]!='e')
            tmp[n++]=op[i];
            strcpy(op,tmp);
            l=strlen(op);
for(n=0;n < l && op[n]!='T';n++);
i=n+1;
            do{
                        op[i+2]=op[i];
                        i++;
            }while(i < l);
            op[n++]='F';
            op[n++]='T';
 op[n++]=39;
            printf("E=%-25s",op);
            printf("T->FT'\n");
 f();
 t_prime();
}
void t_prime(){
int i,n=0,l;
for(i=0;i<=strlen(op);i++)
             if(op[i]!='e')
            tmp[n++]=op[i];
strcpy(op,tmp);
l=strlen(op);
for(n=0;n < l && op[n]!='T';n++);
if(ip_sym[ip_ptr]=='*')            {
                         i=n+2;
 do{
                                    op[i+2]=op[i];
                                    i++;
                        }while(i < l);
                        op[n++]='*';
                        op[n++]='F';
                        op[n++]='T';
                        op[n++]=39;
                        printf("E=%-25s",op);
                        printf("T'->*FT'\n");
                        advance();
                        f();
                        t_prime();
            }
            else{
op[n]='e';
            for(i=n+1;i<=strlen(op);i++)
            op[i]=op[i+1];
            printf("E=%-25s",op);
            printf("T'->e\n");
            }
}
void f(){
int i,n=0,l;
for(i=0;i<=strlen(op);i++)
             if(op[i]!='e')
 tmp[n++]=op[i];
            strcpy(op,tmp);
l=strlen(op);
for(n=0;n < l && op[n]!='F';n++);
            If((ip_sym[ip_ptr]=='i')||(ip_sym[ip_ptr]=='I')){
                        op[n]='i';
                        printf("E=%-25s",op);
                        printf("F->i\n");
                        advance();
            }
            else{
                        if(ip_sym[ip_ptr]=='(')                         {
                                    advance();
                                    e();
                                    if(ip_sym[ip_ptr]==')'){
                                                advance();
                                                i=n+2;
                                                do{
                                                            op[i+2]=op[i];
                                                            i++;
                                                }while(i<=l);
                                    op[n++]='(';
                                    op[n++]='E';
                                    op[n++]=')';
                                    printf("E=%-25s",op);
                                    printf("F->(E)\n");
                        }
            }
            else{
                        printf("\n\t syntax error");
                        getch();
                        exit(1);
                        }
            }
}
void advance(){
            ip_ptr++;
}
void main(){
            int i;
            clrscr();
            printf("\nGrammar without left recursion");
 printf("\n\t\t E->E+T/T \n\t\t T->T*F/F \n\t\t F->(E)/Id ");
 printf("\n Enter the input expression:");
            gets(ip_sym);
            printf("Expressions");
            printf("\t Sequence of production rules\n");
            e();
            for(i=0;i < strlen(ip_sym);i++){
                        if(ip_sym[i]!='+'&&ip_sym[i]!='*'&&ip_sym[i]!='('&&
                        ip_sym[i]!=')'&&ip_sym[i]!='i'&&ip_sym[i]!='I'){
                                    printf("\nSyntax error");
                                    break;
                        }
                        for(i=0;i<=strlen(op);i++)
                        if(op[i]!='e')
                        tmp[n++]=op[i];
                        strcpy(op,tmp);
                        printf("\nE=%-25s",op);
            }
            getch();
}

C Program To Find Follow Of Given String.

#include
#include

intn,m=0,p,i=0,j=0;
char a[10][10],f[10];
void follow(char c);
void first(char c);

int main()
{
inti,z;
charc,ch;
printf("Enter the no.of productions:");
scanf("%d",&n);
printf("Enter the productions(epsilon=$):\n");
for(i=0;i
scanf("%s%c",a[i],&ch);
do{
m=0;
printf("Enter the element whose FOLLOW is to be found:");
scanf(" %c",&c);
follow(c);
printf("FOLLOW(%c) = { ",c);
for(i=0;i
printf("%c ",f[i]);
printf(" }\n");
printf("Do you want to continue(0/1)?");
scanf("%d%c",&z,&ch);
}         
while(z==1);
}
void follow(char c)
{
            if(a[0][0]==c)f[m++]='$';
for(i=0;i
{
for(j=2;j
{
if(a[i][j]==c)
{
if(a[i][j+1]!='\0')first(a[i][j+1]);
if(a[i][j+1]=='\0'&&c!=a[i][0])
follow(a[i][0]);
                                                }
}
}
}
void first(char c){
int k;
if(!(isupper(c)))f[m++]=c;
for(k=0;k
{
if(a[k][0]==c)
{
if(a[k][2]=='$') follow(a[i][0]);
else
if(islower(a[k][2]))f[m++]=a[k][2];

else first(a[k][2]);
}
}

}

C Program To Find First Of Given Sting

#include
#include
void FIRST(char );
intcount,n=0;
charprodn[10][10], first[10];
main(){
inti,choice;
charc,ch;
printf("How many productions ? :");
scanf("%d",&count);
printf("Enter Number Of Productions  :");
for(i=0;i
scanf("%s%c",prodn[i],&ch);
do{
n=0;
printf("Element :");
scanf("%c",&c);
FIRST(c);
printf("\n FIRST(%c)= { ",c);
for(i=0;i
printf("%c ",first[i]);
printf("}\n");
printf("press 1 to continue : ");
scanf("%d%c",&choice,&ch);
}
while(choice==1);
}
void FIRST(char c){
int j;
if(!(isupper(c)))first[n++]=c;
for(j=0;j
if(prodn[j][0]==c){
if(prodn[j][2]=='$') first[n++]='$';
else
if(islower(prodn[j][2]))first[n++]=prodn[j][2];
else FIRST(prodn[j][2]);
}
}

}

Sunday, 24 August 2014

C Program to Draw Pascal's triangle

           1
         1   1
       1   2   1
     1   3   3    1
   1  4    6   4   1
 1  5   10   10  5   1


#include
int main()
{
    int rows,coef=1,space,i,j;
    printf("Enter number of rows: ");
    scanf("%d",&rows);
    for(i=0;i    {
        for(space=1;space<=rows-i;space++)
        printf("  ");
        for(j=0;j<=i;j++)
        {
            if (j==0||i==0)
                coef=1;
            else
               coef=coef*(i-j+1)/j;
            printf("%4d",coef);
        }
        printf("\n");
    }
}

Write a C program to display reverse pyramid.

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


 #include
void  main()
{
    int rows,i,j,space;
    printf("Enter number of rows: ");
    scanf("%d",&rows);
    for(i=rows;i>=1;--i)
    {
        for(space=0;space           printf("  ");
        for(j=i;j<=2*i-1;++j)
          printf("* ");
        for(j=0;j            printf("* ");
        printf("\n");
    }
    return 0;
}

Friday, 22 August 2014

C Program to print half pyramid as using number

#include
int main()
{
    int i,j,rows;
    printf("Enter the number of rows: ");
    scanf("%d",&rows);
    for(i=1;i<=rows;++i)
    {
        for(j=1;j<=i;++j)
        {
           printf("%d ",j);
        }
        printf("\n");
    }
    return 0;
}

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5