C Program To Append Contents Into A File


#include< conio.h >
#include< stdio.h >
#include< process.h >
void main()
{
FILE *fp;
char c;
clrscr();
printf("Contents of the file =>\n");
fp=fopen("demo.txt","r");
while(!feof(fp))
{
c=fgetc(fp);
printf("%c",c);

 }
fp=fopen("demo.txt","a");
if(fp==NULL)
{
printf("file can't append\n");
exit(1);
}
printf("\nEnter the string to append\n");
while(c!='.')
{
c=getche();
fputc(c,fp);
}
fclose(fp);
printf("file contents after appending\n");
fp=fopen("demo.txt","r");
while(!feof(fp))
{
c=fgetc(fp);
printf("%c",c);
}
}

----------------------------------------------------------
OUT PUT:
----------------------------------------------------------
Contents of the file =>
This is c prorgam.

Enter the string to append
I upload C++ prorams soon.

File contents after appending
This is c prorgam.I upload C++ prorams soon.

C Program To Copy The Contents Of A One File To Another File


#include< stdio.h >
#include< conio.h >
#include< stdlib.h >
void main()
 {
FILE *fs,*ft;
char ch;
clrscr();
 fs = fopen("file1.txt","r");
 if(fs==NULL)
  {
 printf("Cannot open source file ! Press key to exit.");
 getch();
 exit(0);
  }
ft = fopen("file2.txt","w");
 if(ft==NULL)
{
printf("Cannot copy file !");
 fclose(fs);
 getch();
 exit(0);
 }
while(1)
 {
ch = getc(fs);
if(ch==EOF)
{
 break;
}
else
putc(ch,ft);
}
printf("File copied succesfully!");
fclose(fs);
fclose(ft);
}

----------------------------------------------------------
OUT PUT:
----------------------------------------------------------

File copied successfully!

C Program To Read And Write The Contents Into Of A File


#include< conio.h >
#include< stdio.h >
#include
void main()
{
FILE *fp;
char c;
clrscr();
fp=fopen("demo.txt","w");
if(fp==NULL)
{
printf("can't open file\n");
exit(1);

}
printf("write data and to stop press =>'.'\n");
while(c!='.')
{
c=getche();
fputc(c,fp);
}
fclose(fp);
printf("\n Read Data from File =>\n");
fp=fopen("demo.txt","r");
while(!feof(fp))
printf("%c",getc(fp));
getch();
}

----------------------------------------------------------
OUT PUT:
----------------------------------------------------------
Write data and to stop press => ’.’
C Programs.
 Read Data from File =>
C Programs.

implement C++ program for abstract classes

#include< iostream.h >
#include< conio.h >
class item
{                                                                                          
private:
int a,b,c,d;
public:
void get();
void multiply();
void sum();
};
void item::get()
{
cout<<"enter a & b :" ;
cin>>a>>b;
}
void item::sum()
{
c=a+b;
cout<<"\n sum is"<< c;
}
void item::multiply()
{
d=a*b;
cout<<"\n multiplication is "<< d;
}
void main()
{
clrscr();
item t;
t.get();
t.sum();
t.multiply();
getch();
}

-------------------------------------------------------
Out put
-------------------------------------------------------
Enter a & b : 5
4
Sum is 9
Multiplication is 20

implement C Program of towers of hanoi


Tower of hanoi is a historical problem, which can be easily expressed using recursion. There are N disks of decreasing size stacked on one needle, and two other empty needles. It is required to stack all the disks onto a second needle in the decreasing order of size. The third needle can be used as a temporary storage. The movement of the disks must confirm to the following rules,

1. Only one disk may be moved at a time
2. A disk can be moved from any needle to any other.
3. The larger disk should not rest upon a smaller one.

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

void move ( int, char, char, char ) ;

void main( )
{
    int n = 3 ;
    clrscr( ) ;
    move ( n, 'A', 'B', 'C' ) ;
    getch( ) ;
}

void move ( int n, char sp, char ap, char ep )
{
    if ( n == 1 )
        printf ("\nMove from %c to %c ", sp, ep ) ;
    else
    {
        move ( n - 1, sp, ep, ap ) ;
        move ( 1, sp, ' ', ep ) ;
        move ( n - 1, ap, sp, ep ) ;
    }
}

implement c program for A bubblesort routine


//program for bubblesort routine

# include <stdio.h>
# include <stdlib.h>
void bubblesort(int array[],int size);

void main()
{
int values[10],j;
for(j=0;j<10;j++)
values[j] = rand()%100;
/*unsorted*/
printf("\nUnsorted values.\n");
for(j=0;j<10;j++)
printf("%d ",values[j]);
/*sorted*/
printf("\nSorted values.\n");
bubblesort(values,10);
for(j=0;j<10;j++)
printf("%d ",values[j]);

}

void bubblesort(int array[],int size)
{
int tmp ,i,j;
for(i = 0;i <size;i++)
for(j=0;j < size;j++)
if(array[i] < array[j])
{
tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}

implement c program to check palindrome string


//program to check whether a string is a palindrome

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main(void)
{
char a[50],b[50];
clrscr();
printf("Enter the string:");
gets(a);
strcpy(b,a);
strrev(a);
if(strcmp(b,a) == 0)
{
printf("The given string is a palindrome!!!");
}
else
{
printf("The given string is not a palindrome!!!");
}
getch();
}

implement c program to count the no words in file


//Program to count the number of words in an input text file

#define NULL 0
FILE *fpt;
void main()
{
 char name[20],c;
 int nw=0;
 clrscr();
 printf("Enter the name of file to be checked:-  ");
 gets(name);
 fpt=fopen(name,"r");
 if (fpt==NULL)
 {
  printf("ERROR - can/'t open file %s",name);
  getch();
  exit(0);
 }
 else
 {
 while ((c=getc(fpt))!=EOF)
 {
  switch(1)
  {
   case 1:
 if (c==' ')
 {
   point: // do
 //    nw=nw+1-1;
  while((c=getc(fpt))==' ');

  if (c!=' ')
nw=nw+1;
  if(c=='
')nw--;
 }


 //  case 3:
 if(c=='
'){
   goto point;}

  }  } }
 printf("The no. of words in %s is %d.  ",name,nw);
 getch();
}

implement c program to Count Blanks,Tabs and Newlines


//Program to Count Blanks,Tabs and Newlines

#include<stdio.h>
int main(void)
{
        int nb,nt,nl,c;
        nb=nt=nl=0;

while((c=getchar())!=EOF)
{
if(c==' ')
++nb;
if(c==' ')
++nt;
if(c=='
')
++nl;
}
printf("No. of Blanks is %d,No. of Tabs is %d and No. of Newlines is %d",nb,nt,nl);
return 0;
}

implement c program for Merge sort


//implement program for Merge sort

#include<stdio.h>

void getdata(int arr[],int n)
{    int i;
      printf("enter the data:");
  for(i=0;i<n;i++)
    {
     scanf("%d",&arr[i]);
    }
}

void display(int arr[],int n)
{
 int i;
 printf(" ");
 for(i=0;i<n;i++)
    {
     printf("%d ",arr[i]);
    }
 getchar();
}

void sort(int arr[],int low,int mid,int high)
{
 int i,j,k,l,b[20];
 l=low;
 i=low;
 j=mid+1;
 while((l<=mid)&&(j<=high))
   {
    if(arr[l]<=arr[j])
      {
       b[i]=arr[l];
       l++;
      }
    else
      {
       b[i]=arr[j];
       j++;
      }
    i++;
   }
 if(l>mid)
   {
    for(k=j;k<=high;k++)
       {
        b[i]=arr[k];
        i++;
       }
   }
 else
   {
    for(k=l;k<=mid;k++)
       {
        b[i]=arr[k];
        i++;
       }
   }
 for(k=low;k<=high;k++)
    {
     arr[k]=b[k];
    }
}

void partition(int arr[],int low,int high)
{
 int mid;
 if(low<high)
   {
    mid=(low+high)/2;
    partition(arr,low,mid);
    partition(arr,mid+1,high);
    sort(arr,low,mid,high);
   }
}
void main()
{
 int arr[20];
 int n;
 printf("Enter number of data:");
 scanf("%d",&n);
 getdata(arr,n);
 partition(arr,0,n-1);
 display(arr,n);
 getchar();
}

implement c program for Fibonacci series


//program to prints the Fibonacci series

#include<stdio.h>
#include<conio.h>
void main(void)
{
int i,j,k,n;
clrscr();
i=0;
j=1;
        printf("Fibonacci series is :--");
printf("%d %d ",i,j);
for(n=0;n<=5;n++)
{
k=i+j;
i=j;
j=k;
printf("%d ",k);
}
getch();
}

Implement C program for Character Generation


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

#include<graphics.h>

void main()
{
 
int gd=DETECT,gm,i,j;
int a[20][20]=

{0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,0},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0},
{0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0},
{0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0}};

Implement C program for Scan Line Polygon Filling


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

main()
{
int n,i,j,k,gd,gm,dy,dx;
int x,y,temp;
int a[20][2],xi[20];
float slope[20];

clrscr();
printf("\n\n\tEnter the no. of edges of polygon : ");
scanf("%d",&n);
printf("\n\n\tEnter the cordinates of polygon :\n\n\n ");

for(i=0;i<n;i++)
{
printf("\tX%d Y%d : ",i,i);
scanf("%d %d",&a[i][0],&a[i][1]);
}

a[n][0]=a[0][0];
a[n][1]=a[0][1];
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");

C program for 3D Tranformations


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<stdlib.h>

int xp[2],yp[2],z;
void display();
void translate();
void scaling();
void rotation();
void matrixmul(int [4][4]);

void main()
{
int gd=DETECT,gm;
int ch,i;
initgraph(&gd,&gm,"c:\\tc\\bgi");
for(i=0;i<2;i++)
{
printf("\nEnter X-coordinate of vertex %d : ",i+1);
scanf("%d",&xp[i]);
printf("\nEnter Y-coordinate of vertex %d : ",i+1);
scanf("%d",&yp[i]);
}
printf("\nEnter The Z-axis For 3d Figure : ");
scanf("%d",&z);
clrscr();
cleardevice();
display(xp,yp);
getche();

implement Perspective projection of 3D objects


#include<stdio.h>
#include<math.h>
#include<graphics.h>
main()
{
int x1,y1,x2,y2,gd,gm;
int ymax,a[4][8];
float par[4][4],b[4][8];
int i,j,k,m,n,p;
int xp, yp, zp, x, y, z;

a[0][0] = 100; a[1][0] = 100; a[2][0] = -100;
a[0][1] = 200; a[1][1] = 100; a[2][1] = -100;

a[0][2] = 200; a[1][2] = 200; a[2][2] = -100;
a[0][3] = 100; a[1][3] = 200; a[2][3] = -100;

a[0][4] = 100; a[1][4] = 100; a[2][4] = -200;
a[0][5] = 200; a[1][5] = 100; a[2][5] = -200;

a[0][6] = 200; a[1][6] = 200; a[2][6] = -200;
a[0][7] = 100; a[1][7] = 200; a[2][7] = -200;

implement Oblique projection of 3D objects


#include<stdio.h>
#include<math.h>
#include<graphics.h>
main()
{
int x1,y1,x2,y2,gd,gm;
int ymax,a[4][8];
float par[4][4],b[4][8];
int i,j,k,m,n,p;
double L1,phi;

a[0][0] = 100; a[1][0] = 100; a[2][0] = 100;
a[0][1] = 200; a[1][1] = 100; a[2][1] = 100;

a[0][2] = 200; a[1][2] = 200; a[2][2] = 100;
a[0][3] = 100; a[1][3] = 200; a[2][3] = 100;

a[0][4] = 100; a[1][4] = 100; a[2][4] = 200;
a[0][5] = 200; a[1][5] = 100; a[2][5] = 200;

a[0][6] = 200; a[1][6] = 200; a[2][6] = 200;
a[0][7] = 100; a[1][7] = 200; a[2][7] = 200;

phi = (double) (3.14*45.0)/180 ;
L1 = 0.5;

implement Mid-Point Ellipse Drawing Algorithm


#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <dos.h>

int main(void)
{
int gd=DETECT,gm;
int cenx,ceny;
float Pk,a,b,x,y;
clrscr();

printf("\n\n Enter 'a' and 'b': ");
scanf("%f%f",&a,&b);
initgraph(&gd,&gm,"c:\\tc\\bgi");
cenx=getmaxx()/2;
ceny=getmaxy()/2;

Pk=b*b-b*a*a+0.25*a*a;
x=0;
y=b;
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);

while (2*x*b*b <= 2*y*a*a)
{
if (Pk<0)
{
x=x+1;
y=y;
Pk=Pk+2*x*b*b+3*b*b;
}
else
{
x=x+1;
y=y-1;
Pk=Pk+2*x*b*b+3*b*b-2*y*a*a+2*a*a;
}
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
delay(40);
}

implement Liang Barsky Line Clipping Algorithm


#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
int gd, gm ;
int x1 , y1 , x2 , y2 ;
int wxmin,wymin,wxmax, wymax ;
float u1 = 0.0,u2 = 1.0 ;
int p1 , q1 , p2 , q2 , p3 , q3 , p4 ,q4 ;
float r1 , r2 , r3 , r4 ;
int x11 , y11 , x22 , y22 ;
clrscr();
printf("Enter the windows left xmin , top boundry ymin\n");
scanf("%d%d",&wxmin,&wymin);
printf("Enter the windows right xmax ,bottom boundry ymax\n");
scanf("%d%d",&wxmax,&wymax);
printf("Enter line x1 , y1 co-ordinate\n");
scanf("%d%d",&x1,&y1);
printf("Enter line x2 , y2 co-ordinate\n");
scanf("%d%d",&x2,&y2);
printf("liang barsky express these 4 inequalities using lpk<=qpk\n");
p1 = -(x2 - x1 ); q1 = x1 - wxmin ;
p2 = ( x2 - x1 ) ; q2 = wxmax - x1 ;
p3 = - ( y2 - y1 ) ; q3 = y1 - wymin ;
p4 = ( y2 - y1 ) ; q4 = wymax - y1 ;
printf("p1=0 line is parallel to left clipping\n");
printf("p2=0 line is parallel to right clipping\n");
printf("p3=0 line is parallel to bottom clipping\n");
printf("p4=0 line is parallel to top clipping\n");

Bresenham Circle Drawing algorithm


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

void main()
{
 int gd=DETECT,gm;
 int r,x,y,p,xc=320,yc=240;
initgraph(&gd,&gm,"C:\\TC\\BGI");
cleardevice();

printf("Enter the radius ");
scanf("%d",&r);

x=0;
y=r;
putpixel(xc+x,yc-y,1);
p=3-(2*r);
for(x=0;x<=y;x++)
{
if (p<0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;
p=p+((4*(x-y)+10));
}

putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,6);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,8);

}
getch();
closegraph();
}



Program to implement Cafeteria problem in java


import java.io.*;
import java.util.*;
class cafe
{
public static void main(String args[])throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader bin=new BufferedReader(isr);
int i,j,k=0,kk,run,counter;
int n=6,m= 5,s=6;
double se[]=new double[10];
int seed=12345;
double r,iat=0,st=0,nat,wt=0,cwt;
double p[]={0.0,0.05,0.4,0.65,0.8,0.9,0.97,1.0};
double at[]={0,0.5,1,1.5,2,2.5,3};
double f[]={0,0.05,0.3,0.65,0.85,1.0};
double t[]={1,2,3,4,5};
Random randy = new Random(12345);

System.out.println("Enter the value of run:");
run=Integer.parseInt(bin.readLine());
for(j=0;j<=s;++j)
{

randy.nextInt(12345);
counter=0;
nat=0;
cwt=0;
for(i=1;i<=j;++i)
{
se[i]=0;
}
cwt=0;
counter=0;
for(counter=1;counter<=run;++counter)
{
r=randy.nextDouble()/32768.0;
for(i=0;i<=n;++i)
{
if(r>p[i] && r<=p[i+1])
iat=at[i];
}
r=randy.nextDouble()/32768.0;
for(i=0;i<=m;++i)
{
if(r>f[i]  && r<=f[i+1])
st=t[i];
}
nat=nat+iat;
double  min=99.9;
for(i=1;i<=j;++i)
{
if(se[i]<=min)
{
min=se[i];
k=i;
}
}
if(nat<=min )
{
se[k]=min+st;
wt=(float)min-nat;
}
else
se[k]=nat+st;
cwt=(float)cwt+wt;
}
System.out.println("server"+" "+" Total arrival" +" " +  "Average waiting time  ");
System.out.println(j+"     "+counter+"   "+(cwt/run)+"    ");
if((cwt/run)<=2)
break;
}

Program toimplement Single Channel Queue in C++

#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<iomanip.h>

void main()
{
clrscr();
int i,j,c,rart[20],rsrt[20],art[20],srt[20],srtb[20],srte[20],cuwq[20],cuss[20],idts[20];
float pa[9],ps[7],iart;
int wtime=0;
float wcust=0.0;
float tservice=0.0;
float tidle=0.0;
float time_arr=0.0;
float time_spent=0.0;
cout<<"Enter no of inter arrival times ( less than 8 minutes)";
cin>>iart;
pa[0]=0;ps[0]=0;
for(i=1;i<=iart;i++)
pa[i]=(float)((1/iart)*1000);

for(i=1;i<=6;i++)
{
cout<<"\nEnter probability for service time "<<i<<" minute";
cin>>ps[i];
ps[i]*=100;
}
cout<<"Enter number of customers (number should be less than 20)";
cin>>c;

PROGRAM TO TEST UNIFORMITY OF RANDOM NO in JAVA


import java.io.*;
import java.util.*;
class randomuni
{ 
  public static void main(String args[])throws IOException
  
  { int i,j;
    int r[]=new int[100];
    
    int arr1[]=new int[100];
    BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
    
    System.out.println("Random number generated using in built function ");
    Random randomGenerator = new Random();
    for (i = 0; i < 100; i++)
    {
      int randomInt = randomGenerator.nextInt(100);
      arr1[i]=randomInt;
      System.out.print(randomInt+" ");
    }

    System.out.println("\nRandom number generated using linear congruential method ");
    System.out.println("Enter the values of X0,a,c and m \n");
    int xo=Integer.parseInt(b.readLine());
    int a=Integer.parseInt(b.readLine());
    int c=Integer.parseInt(b.readLine());
    int m=Integer.parseInt(b.readLine());

    for(i=0;i<100;i++)
    {
    int rand=((a*xo+c)%m);
    r[i]=rand;
    System.out.print(r[i]+" ");
    xo=rand;
    }
    System.out.println("\nSelect any method to test uniformity--1.kolmogorav  2.chi square ");
    i=Integer.parseInt(b.readLine());
    switch(i)
    {
     case 1:double dplus,dminus,dplmax=0,dmimax=0,d,cv=0.410;
            for(i=0;i<99;i++)
            { for(j=i+1;j<100;j++)
              {  if(r[i]>r[j])
                 { int temp=r[i];
                   r[i]=r[j];
                   r[j]=temp; 
                 }
              }
            } 
 

Program to test Independency of RANDOM NO in JAVA

import java.io.*;
import java.util.*;
class randomind
{
  public static void main(String args[])throws IOException
 
  { int i,j;
    int r[]=new int[10];
    double u,var2,var,z,cv=1.96,n1=0,n2=0,mean=49.5;
    int run[]=new int[10];
    int ar=0;
    int arr1[]=new int[10];
    BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
   
    System.out.println("Random number generated using in built function ");
    Random randomGenerator = new Random();
    for (i = 0; i < 10; i++)
    {
      int randomInt = randomGenerator.nextInt(100);
      arr1[i]=randomInt;
      System.out.print(randomInt+" ");
    }

    System.out.println("\nRandom number generated using linear congruential method ");
    System.out.println("Enter the values of X0,a,c and m \n");
    int xo=Integer.parseInt(b.readLine());
    int a=Integer.parseInt(b.readLine());
    int c=Integer.parseInt(b.readLine());
    int m=Integer.parseInt(b.readLine());

Program to Generate RANDOM NO.s in JAVA

import java.io.*;
import java.util.*;
class randomgen
{ 
  public static void main(String args[])throws IOException
  { 
    int i;
    int r[]=new int[10];
    int arr1[]=new int[10];
    BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
    
    System.out.println("Random number generated using in built function ");
    Random randomGenerator = new Random();
    for (i = 0; i < 10; i++)
    {
      int randomInt = randomGenerator.nextInt(100);
      arr1[i]=randomInt;
      System.out.print(randomInt+" ");
    }
    System.out.println("\nRandom number generated using linear congruential method ");
    System.out.println("Enter the values of X0,a,c and m \n");
    int x=Integer.parseInt(b.readLine());
    int a=Integer.parseInt(b.readLine());
    int c=Integer.parseInt(b.readLine());
    int m=Integer.parseInt(b.readLine());
    for(i=0;i<10;i++)
    {
      int rand=((a*x+c)%m);
      r[i]=rand;
      System.out.print(r[i]+" ");
      x=rand;
    }
  }     
}

Program to implement Apriori Algorithm


import java.io.*;
class apriori
{ 
public static void main(String []arg)throws IOException
{
int i,j,m=0;
int t1=0;
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number of transaction :");
int n=Integer.parseInt(b.readLine());
System.out.println("items :1--Milk 2--Bread 3--Coffee 4--Juice  5--Cookies  6--Jam");
int item[][]=new int[n][6];
for(i=0;i<n;i++)
 for(j=0;j<6;j++)
   item[i][j]=0;
String[] itemlist={"MILK","BREAD","COFFEE","JUICE","COOKIES","JAM"};
int nt[]=new int[6];
int q[]=new int[6];
for(i=0;i<n;i++)
{ System.out.println("Transaction "+(i+1)+" :");
  for(j=0;j<6;j++)
  {  //System.out.println(itemlist[j]);
     System.out.println("Is Item "+itemlist[j]+" present in this transaction(1/0)? :");
     item[i][j]=Integer.parseInt(b.readLine()); 
  }
}
 for(j=0;j<6;j++) 
  { for(i=0;i<n;i++)
    {if(item[i][j]==1)
      nt[j]=nt[j]+1;
    }
    System.out.println("Number of Item "+itemlist[j]+" :"+nt[j]);
  }

for(j=0;j<6;j++)
{ if(((nt[j]/(float)n)*100)>=50)
    q[j]=1;
  else
    q[j]=0;

  if(q[j]==1)
   {t1++;
    System.out.println("Item "+itemlist[j]+" is selected "); 
   
   }
}
 for(j=0;j<6;j++) 
  { for(i=0;i<n;i++)
   {
     
     if(q[j]==0)
       { 
        item[i][j]=0;
       }
   }
   }

int nt1[][]=new int[6][6];
 for(j=0;j<6;j++) 
    {  for(m=j+1;m<6;m++) 
       { for(i=0;i<n;i++)
         { if(item[i][j]==1 &&item[i][m]==1)
           { nt1[j][m]=nt1[j][m]+1;
           }
         }
    if(nt1[j][m]!=0)
         System.out.println("Number of Items of  "+itemlist[j]+"& "+itemlist[m]+" :"+nt1[j][m]);
    }
  
   }
for(j=0;j<6;j++)
{ for(m=j+1;m<6;m++) 
  {
  if(((nt1[j][m]/(float)n)*100)>=50)
    q[j]=1;
  else
    q[j]=0;

  if(q[j]==1)
   {
    System.out.println("Item "+itemlist[j]+"& "+itemlist[m]+" is selected "); 
   
   }
}
}
} 
}

/*OUTPUT

Z:\>javac apriori.java

Z:\>java apriori
Enter the number of transaction :
4
items :1--Milk 2--Bread 3--Coffee 4--Juice  5--Cookies  6--Jam
Transaction 1 :
Is Item MILK present in this transaction(1/0)? :
1
Is Item BREAD present in this transaction(1/0)? :
1
Is Item COFFEE present in this transaction(1/0)? :
0
Is Item JUICE present in this transaction(1/0)? :
1
Is Item COOKIES present in this transaction(1/0)? :
1
Is Item JAM present in this transaction(1/0)? :
0
Transaction 2 :
Is Item MILK present in this transaction(1/0)? :
1
Is Item BREAD present in this transaction(1/0)? :
0
Is Item COFFEE present in this transaction(1/0)? :
0
Is Item JUICE present in this transaction(1/0)? :
1
Is Item COOKIES present in this transaction(1/0)? :
0
Is Item JAM present in this transaction(1/0)? :
0
Transaction 3 :
Is Item MILK present in this transaction(1/0)? :
1
Is Item BREAD present in this transaction(1/0)? :
0
Is Item COFFEE present in this transaction(1/0)? :
0
Is Item JUICE present in this transaction(1/0)? :
0
Is Item COOKIES present in this transaction(1/0)? :
0
Is Item JAM present in this transaction(1/0)? :
1
Transaction 4 :
Is Item MILK present in this transaction(1/0)? :
0
Is Item BREAD present in this transaction(1/0)? :
1
Is Item COFFEE present in this transaction(1/0)? :
1
Is Item JUICE present in this transaction(1/0)? :
0
Is Item COOKIES present in this transaction(1/0)? :
1
Is Item JAM present in this transaction(1/0)? :
0
Number of Item MILK :3
Number of Item BREAD :2
Number of Item COFFEE :1
Number of Item JUICE :2
Number of Item COOKIES :2
Number of Item JAM :1
Item MILK is selected
Item BREAD is selected
Item JUICE is selected
Item COOKIES is selected
Number of Items of  MILK& BREAD :1
Number of Items of  MILK& COFFEE :0
Number of Items of  MILK& JUICE :2
Number of Items of  MILK& COOKIES :1
Number of Items of  MILK& JAM :0
Number of Items of  BREAD& COFFEE :0
Number of Items of  BREAD& JUICE :1
Number of Items of  BREAD& COOKIES :2
Number of Items of  BREAD& JAM :0
Number of Items of  COFFEE& JUICE :0
Number of Items of  COFFEE& COOKIES :0
Number of Items of  COFFEE& JAM :0
Number of Items of  JUICE& COOKIES :1
Number of Items of  JUICE& JAM :0
Number of Items of  COOKIES& JAM :0
Item MILK& JUICE is selected
Item BREAD& COOKIES is selected

*/

//Create two file Config.txt & transa.txt put data as follows

Config.txt
81000040

transa.txt
1 2 3 4 5
6 7 8 9 10

shell script code to swap 2 numbers


swap()
{
echo "Enter num1"
read num1
echo "Enter num2"
read num2

temp=$num1
num1=$num2
num2=$temp
echo "swapping numbers"
echo "num1 is $num1"
echo "num2 is $num2"
}
swap


/*
@linux-ogus:~/Desktop> chmod 755 ex2
@linux-ogus:~/Desktop> ./ex2
Enter num1
20
Enter num2
30
swapping numbers
num1 is 30
num2 is 20
*/

shell script code to reverse number


echo "Enter the Number"
read n1
rev=0
a=0
while [ $n1 -gt "0" ]
do
mod=`expr $n1 % 10`
rev=`expr $rev \* 10 + $mod`
n1=`expr $n1 / 10`

done
echo "$rev"

/* OUTPUT
linux-ogus:~> ./reverse_no
Enter the Number
654
456
*/

shell script code to perform arithmatic operations


kk=y
while [ "$kk" != "y" ]
do
echo "Enter value of x"
read x
echo "Enter value of y"
read y
echo "Enter your choice"
echo "1 Add"
echo "2 Sub"
echo "3 Multi"
echo "4 div"
echo "5 i dont know"
read case
case $case in
1) expr $x + $y ;;
2) expr $x - $y ;;
3) expr $x * $y ;;
4) expr $x % $y ;;
5) exit
esac
echo "enter option"
read option
echo "do you want to continue"
read kk
done


/*Output
linux-mj2y:~> sh arith.sh
Enter value of x
3
Enter value of y
5
Enter your choice
1 Add
2 Sub
3 Multi
4 div
5 i dont know
1
8
enter option
y
do you want to continue
n
Enter value of x
3
Enter value of y
3
Enter your choice
1 Add
2 Sub
3 Multi
4 div
5 i dont know
4
0
enter option
kk
do you want to continue
y

*/

shell script code to find greater no


echo "Enter first num"
read n1
echo "Enter the second num"
read n2
echo "Enter the third num"
read n3
if [ $n1 -gt $n2 ]
then
val=$n1
else
val=$n2
fi
if [ $val -gt $n3 ]
then
echo "$val is the greatest num"
else
echo "$n3 is the greatest num"
fi

/* OUTPUT

shell:~> ./greater_no
Enter first num
2
Enter the second num
4
Enter the third num
54
54 is the greatest num
*/

PROGRAM TO MULTITHREADING in JAVA


class a extends Thread
{
public void run()
{
for(inti=0;i<=5;i++)
{
System.out.println(this.getName()+" :"+i);
}
System.out.println("The End of child Thread:"+this.getName());
}
}
class b extends Thread
{
public void run()
{
for(int i=0;i<=5;i++)
{
System.out.println(this.getName()+" :"+i);
}
System.out.println("The End of child Thread:"+this.getName());
}
}

class c extends Thread
{
public void run()
{
for(int i=0;i<=5;i++)
{
System.out.println(this.getName()+" :"+i);
}
System.out.println("The End of child Thread:"+this.getName());
}
}

class test
{
public static void main(String args[])

{
a thra=new a();
b thrb=new b();
c thrc=new c();

thra.setName("Thread_a");
thrb.setName("Thread_b");
thrc.setName("Thread_c");

thra.setPriority(Thread.MAX_PRIORITY);
thrb.setPriority(Thread.MIN_PRIORITY);
thrc.setPriority(Thread.NORM_PRIORITY);

System.out.println("start Thread b...");
thrb.start();

System.out.println("start Thread c...");
thrc.start();

System.out.println("start Thread a...");
thra.start();

try
{

thra.join();
thrb.join();
thrc.join();
}
catch(InterruptedException e)
{}

}
}