Social Icons

Friday, 20 December 2013

IF else program in pl-sql

set serveroutput on;
DECLARE
   total_rows number(2);
BEGIN
   UPDATE e1111
   SET esalary = esalary + 500;
   IF sql%notfound THEN
      dbms_output.put_line('no customers selected');
   ELSIF sql%found THEN
      total_rows := sql%rowcount;
      dbms_output.put_line( total_rows || ' customers selected ');
   END IF;
END;

Function s in PL/SQL

set serveroutput on;
set verify off;
declare
a int;
c int;
b int;

function pied(x in  number)
return number
is
v number(2);
begin
c:=x+10;
return(c);

end pied;


begin
a:=&a;
 b:=pied(a);
dbms_output.put_line(b);
end;

Wednesday, 4 December 2013

calculator Structure in java Applet

import java.awt.*;
import java.awt.event.*;
import java.applet.*;


/*<applet code="carry" width="300" height= "300"></applet>*/

public class carry extends Applet
{
static final int n=3;
int i,j,k;
TextField x;


public void init()
{





setLayout(new BorderLayout());
add(new TextField(15),BorderLayout.NORTH);
setLayout(new FlowLayout(FlowLayout.LEFT));
setFont(new Font("SansSerif",Font.BOLD,30));

add(new Button("+"));
add(new Button("-"));
add(new Button("*"));
add(new Button("/"));


for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
   {
   k=i*n+j;
   if(k>0)
  add(new Button(""+k));
    }

}


}

}

Tuesday, 3 December 2013

Function s in PL/SQL

set serveroutput on;
set verify off;
declare
a int;
c int;
b int;

function pied(x in  number)
return number
is
v number(2);
begin
c:=x+10;
return(c);

end pied;


begin
a:=&a;
 b:=pied(a);
dbms_output.put_line(b);
end;

Function s in PL/SQL

set serveroutput on;
set verify off;
declare
a int;
c int;
b int;

function pied(x in  number)
return number
is
v number(2);
begin
c:=x+10;
return(c);

end pied;


begin
a:=&a;
 b:=pied(a);
dbms_output.put_line(b);
end;

Sum of two no. using procedure in pl/sql

set serveroutput on;
declare
a int;
c int;
b int;

procedure pie(x IN number, y in number ,Z in out number)
is
begin
z:=x+y;
end;



begin
pie(5,6,a);
dbms_output.put_line('hello '||a);
end;

LOCAL PROCEDURE in PL/SQL

set serveroutput on;
declare
a int;
c int;
b int;

procedure pie(x in out number)
is
begin
x:=x+10;


end;

begin
a:=5;
pie(a);

dbms_output.put_line('hello '||a);
end;

IMPLICIT Cursor in PL/SQL

set serveroutput on;
declare
idc number(2);

begin

update e1111 set id=id+500;


if sql%notfound then
dbms_output.put_line('not found');

ELSIF sql%found THEN
      idc := sql%rowcount;
      dbms_output.put_line( idc || ' customers selected ');
   END IF;
END;

PL/SQL While Loop

set serveroutput on;
set verify off;
declare
i int:=1;
j int;
begin
WHILE i<10 loop
dbms_output.put_line(i);
i:=i+1;

end loop;

end;

output :













Printing pattern in PL/SQL

set serveroutput on;
set verify off;
declare
i int;
j int;
begin
for i in 1..5 loop
 dbms_output.put_line('');
 for j in 1..i loop
   dbms_output.put('*');
 end loop;
  dbms_output.new_line;
end loop;

end;

OUTPUT :


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

PL/SQL Simple Loop

set serveroutput on;
set verify off;
declare
b int:=1;
begin

loop
dbms_output.put_line(''||b);
b:=b+1;
exit when b>=10;
end loop;
end;

PL/SQL if-else Statements

set serveroutput on;
set verify off;
declare
a int;
begin
a:=&a;
if a>50 then
dbms_output.put_line('you are old');
elsif a>30 and a<50 then

dbms_output.put_line('you are young');

else

dbms_output.put_line('you are child');

end if;

end;

Thursday, 14 November 2013

Moving fan using java Applet

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="Banner5" width=500 height=500>
</applet>
*/
public class Banner5 extends Applet implements Runnable,MouseListener,MouseMotionListener{

Thread t = null;

Thread t1 = null;
int x,y,state;
boolean stopFlag,st1;
// Set colors and initialize thread.
public void init() {
setBackground(Color.cyan);
setForeground(Color.red);
addMouseListener(this);
addMouseMotionListener(this);
}

public void mouseClicked(MouseEvent me)
{
t1 = new Thread(this);
stopFlag = false;
t1.start();

}
public  void mouseEntered(MouseEvent me)
{
t = new Thread(this);
stopFlag = false;
t.start();



}
public  void mouseExited(MouseEvent me)
{
stopFlag = true;
st1=true;
showStatus("Exited");
}

public  void mousePressed(MouseEvent me)
{}
public  void mouseReleased(MouseEvent me)
{}







public void mouseMoved(MouseEvent me)
{
 //repaint();

showStatus("hello");
}



public void run() {
char ch;

for( ; ; ) {
try {



repaint();
Thread.sleep(300);
x=x+10;
y=y+10;



if(stopFlag)
break;
} catch(InterruptedException e) {}
}
}


public void mouseDragged(MouseEvent me)
{

}















// Start thread
public void start() {
t = new Thread(this);
stopFlag = true;
t.start();
x=0;
}

// Pause the banner.
public void stop() {
stopFlag = true;
t = null;
}
// Display the banner.
public void paint(Graphics g) {

g.fillArc(100, 40, 100, 100, 0+x, 45);
g.fillArc(100, 40, 100, 100, 120+x, 45);
g.fillArc(100, 40, 100, 100, 240+x, 45);


g.fillArc(100, 200, 100, 100, 240-y, 45);
g.fillArc(100, 200, 100, 100, 120-y,45);
g.fillArc(100, 200, 100, 100, 0-y, 45);

}
}

Saturday, 26 October 2013

Right Moving String in Java Applet

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*

<applet code=jitender width=400 height=400>
</applet>

*/


public class jitender extends Applet implements Runnable
{
Thread t=null;
boolean stopflag;
String msg,ch1;





  public void init()
  {
  setBackground(Color.cyan);
  setForeground(Color.red);
 }

 public void start()
  {
  msg="A simple jitender moving";
if(msg==null)
 {
  msg="message not found";
 }
msg=" "+msg;
 t=new Thread(this);
 stopflag=false;
  t.start();
}

public void run()
{
char ch;
String ch1;

 char p1[]=msg.toCharArray();
for( ; ;)
{
 try
   {
repaint();
Thread.sleep(250);

ch=p1[p1.length-1];

for(int i=p1.length-1;i>0;i--)
{
   p1[i]=p1[i-1];
 }
 p1[0]=ch;
ch1= String.valueOf(p1);
 msg=ch1;












   if(stopflag)
    {
    break;
     }


   }catch(InterruptedException e){}


}

}

public void stop()
{
   stopflag=true;
    t=null;
}

public void paint(Graphics g)
{
g.drawString(msg,50,30);
}

}

Sunday, 20 October 2013

dbms pl/sql curser

set serveroutput on;
DECLARE
   total_rows number(2);
BEGIN
   UPDATE e1111
   SET esalary = esalary + 500;
   IF sql%notfound THEN
      dbms_output.put_line('no customers selected');
   ELSIF sql%found THEN
      total_rows := sql%rowcount;
      dbms_output.put_line( total_rows || ' customers selected ');
   END IF;
END;

Sunday, 29 September 2013

Exception handling in java

class ex
{

 public static int quotient(int a,int b)
{

   if(b==0)
  {
  throw new ArithmeticException("divide by zero") ;
  }
 return a/b;


}


 public static void main(String args[])
 {
 int c;
 int a=5,b=0;
 

       
  try
  {
   c=quotient(a,b);
  System.out.println("the value of a/b is "+c);

  }



 catch(ArithmeticException e)
 {
  System.out.println("the b value can not be negative :");
 System.out.println(" :"+e.getMessage());
  System.out.println(" :"+e.toString());

  e.printStackTrace();
 }


     finally
       {
          System.out.println("hello finally is executed ");
 
              }            


}


}

Saturday, 28 September 2013

String character interchange in java

class str
{
public static void main(String args[])
{
String s="this is lecture class";
char temp;
String a[]=s.split(" ");

System.out.println("..........the String  are  ...... ");

for(int i=0;i<a.length-1;i++)
{
System.out.print("  "+a[i]);

}


System.out.println("  ");

for(int i=0;i<a.length-1;i++)
{
char p[]=a[i].toCharArray();
for(int j=0;j<p.length-1;j=j+2)
 {
  temp=p[j];
  p[j]=p[j+1];
  p[j+1]=temp;

}

 a[i]=new String(p);

}

System.out.println("..........the String after interchange of character ...... ");
for(int i=0;i<a.length-1;i++)
{
System.out.print("  "+a[i]);

}





}
}

Wednesday, 25 September 2013

check palindrome in java

import java.util.Scanner;
class pldm
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a String which is palindrome ");
String s=in.nextLine();

if(ispalindrome(s))
{
System.out.println("word is palindrome");
}
else
System.out.println("word is not palindrome");
}

public static boolean ispalindrome(String s1)
{
int low=0;
int high=s1.length()-1;

  while(low<high)
{
if(s1.charAt(low)!=s1.charAt(high))
 {
return false;
 }
low++;
high--;
 }
 return true;

}
}







getrlimit and setrlimit function

#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main (int argc, char *argv[])
{
  struct rlimit limit;
  
  /* Set the file size resource limit. */
  limit.rlim_cur = 65535;
  limit.rlim_max = 65535;
  if (setrlimit(RLIMIT_FSIZE, &limit) != 0) {
    printf("setrlimit() failed with errno=%d\n", errno);
    exit(1);
  }

  /* Get the file size resource limit. */
  if (getrlimit(RLIMIT_FSIZE, &limit) != 0) {
    printf("getrlimit() failed with errno=%d\n", errno);
    exit(1);
  }

  printf("The soft limit is %llu\n", limit.rlim_cur);
  printf("The hard limit is %llu\n", limit.rlim_max);
  exit(0);
}

Tuesday, 24 September 2013

getenv and putenv function

#include <stdlib.h>
#include <stdio.h>

int main(int argc , char *argv[])
{
putenv("JITENDER= /hi/i m coming/ ");

printf("\n variable is %s ",getenv("JITENDER"));

return 0;

}

getenv function in linux

                                                                                         

#include <stdlib.h>
#include <stdio.h>

int main(int argc , char *argv[])
{


printf("\n variable is %s ",getenv(argv[1]));

return 0;

}



Saturday, 21 September 2013

Sum Of all cross diagonals of an array

import java.util.Scanner;
class Array
{
public static void main(String args[])
{int l,k;
int count=0,sum=0;
 int a[][]=new int[4][4];
 int i,j,c;
Scanner s= new Scanner(System.in);

System.out.println("Enter element Of the array : ");
for(i=0;i<a.length;i++)
{
for(j=0;j<a[i].length;j++)
{
a[i][j]=s.nextInt();
}

}

System.out.println(" Element Of the array are : ");
for(i=0;i<a.length;i++)
{
for(j=0;j<a[i].length;j++)
{
System.out.print(" "+a[i][j]);
}
System.out.println("");

}

l=a.length-2;

System.out.println("Sum of the Diagonals Element Of the array are : ");
System.out.println("element at the  left    corner is  : "+a[a.length-1][0]);
for(c=l;c>=0;c--)
{
for(i=0;i<a.length;i++)
{
for(j=0;j<a.length;j++)
{

   if(i==(j+c))
   {  
   count=count+a[i][j];
    }
 
 }
 }

 System.out.println("Sum of diagonal starting at row "+"is:"+count);



count=0;

}


for(c=1;c<a.length-1;c++)
{
for(i=0;i<a.length;i++)
{
for(j=0;j<a.length;j++)
{

   if(i+c==j)
   {  
   count=count+a[i][j];
    }
 
 }
 }

 System.out.println(" Sum of diagonal starting at row "+"is :  "+count);



count=0;

}


System.out.println(" element  at  the   right corner is: "+a[0][a.length-1]);

}
}

world replacement in String program in java

class Com_pare
{

public static void main(String args[])
{

int i=0,m,t,n,o,c=0;
String search="six";
String s1="welcomlce to jalcva";
String s2="six pack is alwas six in the interval of six";
String p;
String x;

char a[]=s2.toCharArray();
for(i=0;i<a.length;i++)
{
 if(a[i]=='s' && a[i+1]=='i' && a[i+2]=='x')
{
 
c=c+1;
}
}



for(t=0;t<c;t++)
{
m=s2.indexOf("six");
s2=s2.substring(0,m)+"was"+s2.substring(m+search.length(),s2.length());
}


System.out.println(" String After replacement "+s2);
System.out.println(" no. of timelc occurs  "+c);


}



}

Monday, 16 September 2013

insertion sort in java


import java.util.Scanner;
class insert
{
  public static void main(String args[])
  {
  Scanner s = new Scanner(System.in);
  int i,b,c,temp;
  int j;
  int a[] = new int[5];
  System.out.println("\n Enter Element into the array: ");
  for(i=0;i<5;i++)
  {
   a[i]=s.nextInt();
  }
  System.out.println("\n The Element into the array are : ");
  for(i=0;i<5;i++)
  {
   System.out.print(a[i]+" ");
  }




   for(i=0;i<5;i++)
   {
    temp=a[i];
j=i-1;
   while(j>=0 && temp<a[j])
    {
      a[j+1]=a[j];

 j=j-1;
}
 a[j+1]=temp;

 
  }

    System.out.println("\n The Element after sorting into the array are : ");
  for(i=0;i<5;i++)
  {
   System.out.print(a[i]+" ");
  }





 }

}

Friday, 6 September 2013

Anonymous array


class Arr
{
static int i=5;

 static void F(int p[])
  {
  for(i=0;i<p.length;i++)
  {
  System.out.print(p[i]+" ");
 
   }
   }



 public static void main(String args[])
 {
  Arr a= new Arr();
   int i,j;

   F(new int[] {1,2,3,4});
 


  }

}

Wednesday, 4 September 2013

Dynamic Dispatch With abstract Function

abstract class A
{
int d1;
int d2;

abstract double area();

 A(int a, int b)
{
d1=a;
d2=b;

}

}


class B extends A
{
  B(int a,int b)
  {
  super(a,b);
  }

  double area()
  {
   return (d1*d2);
  }


}




class C extends A
{
 C(int a, int b)
 {
  super(a,b);
 }

 double area()
{
return d1*d2;
}

}

class over
{
public static void main(String args[])
{
C c=new C(5,3);
B b=new B(4,5);
A r;
r=c;
System.out.println(r.area());
r=b;
System.out.println(r.area());

}
}

Dynamic Method dispatch

class A
{


void show()
{
System.out.println("\n it is of a class");
}

}


class B extends A
{
void show()
{

System.out.println("\n it is of B class");
}


}




class C extends B
{
void show()
{

System.out.println("\n it is of C class");
}

}

class over
{
public static void main(String args[])
{
C c=new C();
A a =new A();
B b=new B();
A r;
r=a;
a.show();
r=b;
b.show();
r=c;
r.show();
}
}

Function overriding In java

class A
{


void show()
{
System.out.println("\n it is of a class");
}

}


class B extends A
{
void show()
{
super.show();
System.out.println("\n it is of B class");
}


}




class C extends B
{
void show()
{
super.show();
System.out.println("\n it is of C class");
}

}

class over
{
public static void main(String args[])
{
C c=new C();
c.show();
}
}

use of Super Keyword

class Box
{
double width;
double height;
double depth;

 Box(Box ob)
 {
  width=ob.width;
  height=ob.width;
  depth=ob.depth;
 }

 Box(double w, double h,double d)
 {
  width=w;
  height=h;
  depth=d;
 }
  Box(double d)
  {
  width=d;
  height=d;
  depth=d;

  }

 void volume()
 {

 System.out.println("\n the volume is " +width*height*depth);
 }
}

class B extends Box
{
double weight;
 B(double a,double b,double c, double d)
 {
 super(a,b,c);
 weight=d;
 }
  void show()
  {
 System.out.println("\n Weight is "+weight);
  }


}

class C
{
public static void main(String args[])
{
B ob=new B(5,6,10,4);
 ob.volume();
 ob.show();
}

}

Friday, 23 August 2013

Generating Random No. In java

import java.util.Random;
class Run
{

public static void main(String args[])
{
 int i;
 Random d = new Random(3);
 Random d1 = new Random(0);
 for(i=0;i<10;i++)
 {
 System.out.println("Print Random value having seed 3  " + d.nextInt(1000));
System.out.println("Print Random value having seed 0 : "+d1.nextInt(1000));
 }
 }

}

output:

Print Random value having seed 3  734
Print Random value having seed 0 : 360
Print Random value having seed 3  660
Print Random value having seed 0 : 948
Print Random value having seed 3  210
Print Random value having seed 0 : 29
Print Random value having seed 3  581
Print Random value having seed 0 : 447
Print Random value having seed 3  128
Print Random value having seed 0 : 515
Print Random value having seed 3  202
Print Random value having seed 0 : 53
Print Random value having seed 3  549
Print Random value having seed 0 : 491
Print Random value having seed 3  564
Print Random value having seed 0 : 761
Print Random value having seed 3  459
Print Random value having seed 0 : 719
Print Random value having seed 3  961
Print Random value having seed 0 : 854

Printing Date in java Program

import java.util.Date;
class New
{

public static void main(String args[])
{

 Date d = new Date();

 System.out.println("Time in millisecond is from 1 jun 1970 " + d.getTime());
System.out.println("Current Date and Time is : "+d.toString());
 }


}

output:

   e:\java_programs>java New
Time in millisecond is  1377282070857
Current Date and Time is : Fri Aug 23 23:51:10 IST 2013

Command line Input Java Program


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

 int a = Integer.parseInt(args[0]);
 int b= Integer.parseInt(args[1]);

 int c=a+b;
 System.out.println("Addition of two no . is  "+c);
}


}


output:

               

e:\java_programs>java New 5 6
Addition of two no . is  11


Java Program Using Scanner class to take Input from user

import java.util.Scanner;
class New
{
public static void main(String args[])
{
 Scanner s= new Scanner(System.in);
 System.out.println("Enter an integer value ");

 int a = s.nextInt();
 System.out.println("Enter 2nd integer");
 int b= s.nextInt();
 int c=a+b;
 System.out.println("Addition of two no. is "+c);
}


}


output:


      e:\java_programs>java New
Enter an integer value
25
Enter 2nd integer
36
Addition of two no. is 61

Full Duplex Mode Communication Using Pipe

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/ipc.h>
#include<sys/types.h>
int main()
{
int p1[2],p2[2],i;
char buf[20];
pipe(p1);
pipe(p2);
if(fork()==0)
{
printf("\n this is child(the input text is text)\n");
close(p1[1]);
close(p2[0]);
read(p1[0],buf,20);
write(p2[1],"Hello Papa ! I m fine",25);
printf("\n Parent send the message : %s \n",buf);

}
else
{
printf("\n this is parent(the output text is text)\n");
close(p2[1]);
close(p1[0]);
write(p1[1],"how r u beta",20);

read(p2[0],buf,20);
printf("\n child sending message to parent : %s \n",buf);

}
return 0;
}


Output:
             

Using Fork Command getting Process Id Of Child

#include<sys/types.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
int pid;
pid=fork();
if(pid==0)
{
printf("\n the process id of child is %d",getpid());
printf("\n the parent process id of child  is %d",getppid());
}

else
{
printf("\n the process id of parent is %d",getpid());
printf("\n the parent process id of parent  is %d",getppid());
}

return 0;

}

Thursday, 1 August 2013

How to increase bandwidth of your internet

Here's a simple little thing you can do to increase your bandwidth by at least 20%. 

Ok here we go,  

1.) log on as Administrator. 

2.) start - run - type gpedit.msc 

3.) expand "local computer policy" 

4.) then expand "administrative templates" 

5.) then expand "network branch" 

6.) Highlight/double click the "QoS Packet Scheduler" 

7.) on right window double click "limit reservable bandwidth" 

8.) on setting tab check the "enabled" 

9.) change "Bandwidth limit %" to 0 

You're done.It would be a good idea to reboot after this.


Why did we do that? Simple, Windows is silently eating 20% of your bandwidth. I emphasize on the word “silently” - Remember.

Saturday, 4 May 2013

Reversing a linked list inserted from begining


#include<iostream>
#include<conio.h>
using namespace std;
struct link
{
 int data;
 struct link *next;
 struct link *pre;
};
struct link *newn,*loc, *start,*ptr,*end;
void binsert();
void einsert();
void minsert();
void sinsert();
void reverse();
void display();
int main()
{char ch;
int op;
for(int i=0;i<5;i++)
{

 binsert();
 display();
}
cout<<"\n reverse of the linked list : ";
   reverse();
 
getch();
}


void display()
{
ptr=start;
while(ptr!=NULL)
{
cout<<" "<<ptr->data;
cout<<"-->";
ptr=ptr->next;
}
}



void binsert()
{
int item;
cout<<"\n Enter item to insert in begining :";
cin>>item;
newn = new struct link[1];
newn->data=item;
newn->next=NULL;
newn->pre=NULL;
//tr=start;
loc=end;
if(end==NULL)
{
start=newn;
end=newn;
}
else
{
while(loc->pre!=NULL)
{
loc=loc->pre;
}
 // newn->next=start;
loc->pre=newn;
  newn->next=loc;
  start=newn;




}

}

 void reverse()
 {
  loc=start;
  while(loc!=NULL)
  {
  cout<<" "<<loc->data;
cout<<"-->";
loc=loc->next;
 
  }
 }











Friday, 3 May 2013

Time Using Strftime Function


#include<unistd.h>
#include<time.h>
#include<stdio.h>
int main()
{
time_t t1,t2;
struct tm *tm_ptr;
int m,p,u;
char *n;
char buf[256];
time(&t1);

tm_ptr=localtime(&t1);

strftime(buf,256,"%A:%d:%B:%I:%S:%p",tm_ptr);
printf("\n time is %s",buf);

return 0;
}

Time Using Ctime Function


#include<unistd.h>
#include<time.h>
#include<stdio.h>
int main()
{
time_t t1,t2;
struct tm *tm_ptr;
int m,p,u;
char *n;
time(&t1);

n=ctime(&t1);


printf("\n time is %s",n);
return 0;
}



Time Using Localtime Function


#include<unistd.h>
#include<time.h>
#include<stdio.h>
int main()
{
time_t t1,t2;
struct tm *tm_ptr;
int m,p,u;
char *n;
time(&t1);

tm_ptr=localtime(&t1);


printf("\n year %2d  : mon %2d    hour  %2d, Minute %2d , Second %2d",tm_ptr->tm_year+1900,tm_ptr->tm_mon+1,tm_ptr->tm_hour,tm_ptr->tm_min,tm_$
return 0;
}

Time Function Using C program


#include<unistd.h>
#include<time.h>
#include<stdio.h>
int main()
{
time_t t1,t2;
int m,p,u;
char *n;
time(&t1);

m=t1;
printf("\n time is %d",m);

printf("\n enter your name :");
scanf("%s",n);

time(&t2);

p=t2;
printf("\n time is %d",p);

u=p-m;
printf("\n time taken in writing name is : %d",u);


return 0;
}

Thursday, 2 May 2013

Thread cancelletion Using Deferred Cancel Type


#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<string.h>
void  *func1(void *arg);
char m[]="hi how r u";

int main()
{
int r,x;
void *p;
pthread_t a;
r=pthread_create(&a,NULL,func1,(void *)m);
if(r!=0)
{

perror("thread creation failed : ");
exit(EXIT_FAILURE);
}
else
sleep(3);
x=pthread_cancel(a);
if(x==-1)
{
perror("thrAed cancel failed ");


}

else
sleep(3);
x=pthread_cancel(a);
if(x==-1)
{
perror("thrAed cancel failed ");


}
else
{
printf("\n thread cancelled");

r=pthread_join(a,&p);
if(r!=0)
{
perror("thread joining failed :");
exit(EXIT_FAILURE);
}
printf("\n thread joined with value %s ", (char *)p);
printf("\n messafe is %s",m);
exit(EXIT_SUCCESS);
}
}



Wednesday, 1 May 2013

Machine Information Using Library Function getuid,getgid,gethostname


#include<stdio.h>
#include<sys/types.h>
#include<sys/utsname.h>
#include<unistd.h>
#include<stdlib.h>
#include<pwd.h>
int main()
{
uid_t uid;
gid_t gid;
char s[100];
struct passwd *pw;
struct utsname uts;

uid=getuid();
gid=getgid();

printf("\n userid : %d  , groupid : %d ",uid,gid);
printf("\n login name : %s ",getlogin());

  pw=getpwuid(uid);
printf("\n uid : %d , gid :  %d , name : %s",pw->pw_uid,pw->pw_gid,pw->pw_name);

gethostname(s,255);
printf("\n host name : %s",s);

uname(&uts);

printf("\n machine name :  %s , \n  sysname :  %s ,\n  version : %s ,\n Nodename : %s ,\n  ",uts.machine,uts.sysname,uts.version,uts.nodename);
return 0;
}

Sum And Product Using Getopt Function


#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main(int argc , char *argv[])
{

int n,i,sum=0, pr=1;
int a,b;
while((n=getopt(argc,argv,":if:::l::r"))!=-1)
{
 switch(n)
 {
 case 'i' :
 case 'r' : printf("\n option %c",n);
              break;
 case 'f'  :// printf("\n filename %s",optarg);
                a=optind;
               for(;optind<a+3;optind++)
                 {
                    i=atoi(argv[optind]);
                    sum=sum+i;
                  }
                    printf(" \n sum of the two no :  %d ",sum);
                 break;
 case 'l'  :     b=optind;
                 for(;optind<b+2;optind++)
                 {
                    i=atoi(argv[optind]);
                    pr=pr*i;
                  }
                 printf(" \n Product  of the two no :  %d ",pr);
                 break;

 case '?'  : printf("\n unknown option %c",optopt);
               break;
 case ':'  : printf("\n argument needed : ");
              break;
 }

 }

           for(;optind<argc;optind++)
    {
    printf(" \n arguments : %s ",argv[optind]);
    }


return 0;
}


             
             

Copying Files content Using Read & write system call


#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

int main()
{
int nread;
char buf[150];
int  m,n,o;
m=open("kaha", O_RDONLY,S_IRUSR|S_IWUSR);
if(m==-1)
{
printf("\n Error Occured : ");
}

n=open("tu.txt",O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR);
if(n==-1)
                {

printf("\n Error Occured : ");

}

lseek(m,2,SEEK_SET);
lseek(n,5,SEEK_SET);

while(nread=read(m,buf,sizeof(buf)))
{
  write(n,buf,10);
}



return 0;
}

Reading Files Of a Directory


#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<dirent.h>
struct dirent *p;
int main()
{
DIR *q;
int  m;
q=opendir("1");
if(q==NULL)
{
printf("\n Error Occured : ");

}

else
{
printf("\n  File Name  |||||||     Inode No.\n");
printf("......................................");
while(p=readdir(q))
{

printf("\n %s",p->d_name);
m=p->d_ino;
printf("\t\t\t %d",m);
}
}
closedir(q);
return 0;
}


1 12 123 1234 12345 Pattern Using Shell Programme


#!/bin/sh
c=6;
m=1;
for((i=1;i<=5;i++))
do
for((k=1;k<=c;k++))
do
  echo -n  " "
done
for((j=1;j<=i;j++))
do
echo -n "$j"
echo -n " "
done
c=$(($c-1))
echo -e " "
done


exit 0


Loop Patterns Using Shell Commands


#!/bin/sh
c=5;
for((i=1;i<=5;i++))
do
for((k=1;k<=c;k++))
do
  echo -n  " "
done
for((j=1;j<=i;j++))
do
echo -n "*"
echo -n " "
done
c=$(($c-1))
echo -e " "
done


exit 0

Output :

Geometric Progression Using shell


#!/bin/sh

echo -n "Enter First No. of G.P :  "
read  a
echo -n "Enter Common Ratio of G.p :"
read r
echo -n  "how many no. you want to print : "
read  n
echo " .............G.p is : ........   "

while [ $n -gt 0 ]
do
echo -n "$a "
a=$(($a*$r))
n=$(($n-1))
done

exit 0

Cheking Number is Palindrome


#!/bin/sh

echo -n "Enter any no to find Reverse :  "
read  n
p=$n
rev=0
while [ $n -gt 0 ]
do
z=$(($n%10))
n=$(($n/10))
rev=$(($(($rev*10)) + z))
done
echo " .............reverse of the no. is : ........   : $rev"

if [ $rev -eq $p ]
then
echo "............Number is Palindrome.......... "
else
 echo  "........Number  is Not Palindrome ............."
fi
exit 0
output : 

Reverse Of a No.


#!/bin/sh

echo -n "Enter any no to find Reverse :  "
read  n
p=$n
rev=0
while [ $n -gt 0 ]
do
z=$(($n%10))
n=$(($n/10))
rev=$(($(($rev*10)) + z))
done
echo " .............reverse of the no. is : ........   : $rev"
exit 0
Output :



Factorial Of a No. Using Shell Program



#!/bin/sh
fact=1;
echo -n "Enter any no to find factorial :  "
read  n
for((i=1;i<=n;i++))
do
((fact=$fact * $i))

done

echo " .............factorial of the no. is : ........   : $fact"
exit 0


Shell Programming [If- Else]


#!/bin/sh
echo -n "Enter how many times you want to enter  :  "
read d
for((i=0;i<d;i++))
do
echo -n "Enter your age :  "
read n
if [ $n -gt 20 ] && [ $n -lt 50 ]
then
echo "...........you are middle aged men...................... "
elif [ $n -gt 5 ] && [ $n -lt 20 ]
then
echo "................you r a boy................"
else
 echo ".............you are a old man ............. "
fi
done
exit 0

Output:

Excuting Command in C program using "system" function


#include<stdio.h>
#include<stdlib.h>
int main()
{
printf("\n Showing Details of A file using System command : \n");


system("more first.txt");
return 0;


}



Saturday, 27 April 2013

Creating Child Process Using Fork


#include<sys/types.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
pid_t pid;
pid=fork();
int n;
char *m;
switch(pid)
{
case -1  : printf("\n Error ocured : ");
           break;
case 0 :
              n=3;
            m="child process is running : ";
             break;
default :
              n=3;
            m="parent process is running : ";
                 break;
}


for(;n>0;n--)
{
 puts(m);
 sleep(1);


}

return 0 ;
}


Output :
 

Preorder and Postorder Tree Implementation Using Linked List


#include<iostream>
#include<string.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
int top=0;
struct node
{
int info;
node * right;
node * left;
}*newptr,*root,*par,*ptr,*pos,*save,*loc,*child,*parsuc,*suc,*s,*stack[10];
void ins(int);
void show();
void disp();
void view();
void find(int);
int main()
{
root=NULL;
//clrscr();
int a,item;
char ch;
int i,n;
cout<<"\n enter limit : ";
cin>>n;
cout<<"\n\n\n\tEnter the item to insert: ";
for(i=0;i<n;i++)
{ cin>>a;
ins(a);
}
stack[top]=NULL;
               
cout<<"\n\t Pre-order of tree :\t";
disp();
cout<<"\n\t In-order of tree :\t";
show();

getch();

}
void ins(int a)
{
newptr=new node[1];
newptr->info=a;
newptr->right=newptr->left=NULL;

if(root==NULL)
{
root=newptr;
}
else
{
ptr=root;
while(ptr!=NULL)
{
if(ptr->info>=a)
{
if(ptr->left==NULL)
{
ptr->left=newptr;
break;
}
ptr=ptr->left;
}
else
{
if(ptr->right==NULL)
{
ptr->right=newptr;
break;
}
ptr=ptr->right;
}
}
}
}
void disp()
{

ptr=root;
top=0;
while(ptr!=NULL)
{       cout<<"\t"<<ptr->info;
if(ptr->right!=NULL)
{       top++;
stack[top]=ptr->right;
}
if(ptr->left!=NULL)
{
ptr=ptr->left;
}
else
{    
ptr=stack[top--];
}

}

}

  void show()
  {
  ptr=root;
  x: while(ptr!=NULL)
  {
 
  top=top+1;
  stack[top]=ptr;
 
  ptr=ptr->left;
    }
 
    ptr=stack[top];
    top=top-1;
    while(ptr!=NULL)
    {
    cout<<"\t "<<ptr->info;
     if(ptr->right!=NULL)
        {
         ptr=ptr->right;
         goto x;
        }
 
     ptr=stack[top];
    top=top-1;
 
  }
     

    }
 











   
   
   
   
   

 

Friday, 26 April 2013

Merge Sort Using arrays in Decreasing Order

#include<iostream>
#include<conio.h>
using namespace std;
int  merge(int a[],int m,int b[],int n,int c[],int p);
 int main()
{
    int a[10],b[10],c[10];
    int m,n,p;
   
   
        cout<<"\n Enter size of First array : ";
        cin>>m;
    cout<<"\n\t Enter element of First array : \n";
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
               
    }
   
      cout<<"\n Enter size of Second array  : ";
        cin>>n;
    cout<<"\n\t Enter element of Second array  : \n";
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
               
    }
   
     
   

   merge(a,m,b,n,c,p);
   cout<<"\n after merging : ";
  
   for(int k=0;k<m+n;k++)
   {
      
       cout<<" "<<c[k];
   }
  
  

getch();

}


int  merge(int a[10],int m,int b[10],int n,int c[10],int p)
{
     int i=0;
     int j=0;
     int k=0;
  while(i<m && j<n)
  {
      if(a[i]>=b[j])
      {
          c[k]=a[i];
          i++;
      }
      else if(a[i]<=b[j])
      {
          c[k]=b[j];
          j++;
      }
     
   k++;
  }
 
  if(i==m && j<n)
  {
      c[k]=b[j];
      j++;
      k++;
     
  }
    if(j==n && i<m)
  {
      c[k]=a[i];
      i++;
     k++;
     
  }
   


}


Output :





Selection Sort Using arrays


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{

int a[100],i,n,p,k,min,loc,temp;

cout<<"\n------------ SELECTION SORT ------------ \n\n";
cout<<"Enter No. of Elements=";
cin>>n;

cout<<"\nEnter Elements=\n";
for(i=1;i<=n;i++)
{
cin>>a[i];
}

for(p=1;p<=n-1;p++)              // Loop for Pass
{
min=a[p];                        // Element Selection
loc=p;

for(k=p+1;k<=n;k++)              // Finding Min Value
{
if(min>a[k])
{
min=a[k];
loc=k;
}
}

temp=a[p];                        // Swap Selected Element and Min Value
a[p]=a[loc];
a[loc]=temp;

}

cout<<"\nAfter Sorting : \n";

for(i=1;i<=n;i++)
{
cout<<a[i]<<endl;
}

getch();
}

Merge sort using arrays


#include<iostream>
#include<conio.h>
using namespace std;
int  merge(int a[],int m,int b[],int n,int c[],int p);
 int main()
{
int a[10],b[10],c[10];
int m,n,p;


cout<<"\n Enter size of First array";
   cin>>m;
cout<<"\n Enter element of First array";
for(int i=0;i<m;i++)
{
cin>>a[i];

}

  cout<<"\n Enter size of Second array";
   cin>>n;
cout<<"\n Enter element of Second array";
for(int i=0;i<n;i++)
{
cin>>b[i];

}

 


   merge(a,m,b,n,c,p);
   cout<<"\n after merging : ";
 
   for(int k=0;k<m+n;k++)
   {
   
    cout<<" "<<c[k];
   }
 
 

getch();

}


int  merge(int a[10],int m,int b[10],int n,int c[10],int p)
{
  int i=0;
  int j=0;
  int k=0;
  while(i<m && j<n)
  {
  if(a[i]<=b[j])
  {
  c[k]=a[i];
  i++;
  }
  else if(a[i]>=b[j])
  {
  c[k]=b[j];
  j++;
  }
 
   k++;
  }

  if(i==m && j<n)
  {
  c[k]=b[j];
  j++;
  k++;
 
  }
if(j==n && i<m)
  {
  c[k]=a[i];
  i++;
     k++;
 
  }



}



output:






 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management