Showing posts with label Programs. Show all posts
Showing posts with label Programs. Show all posts

Tuesday, November 13, 2018

PHP programs to CRUD in php

<?php
include("./connect.php");
if(isset($_POST['btnReg'])){
$name=$_POST['txtnm'];
$gen=$_POST['rdbgen'];
$cno=$_POST['txtcno'];
$addr=$_POST['txtaddr'];
$h=$_POST['chk'];
$desg=$_POST['selDesg'];
$hobby=implode(",",$h);
$sql="insert into tblPerson(pname,gender,contactNo,hobbies,address,designation) values('".$name."','".$gen."','".$cno."','".$hobby."','".$addr."','".$desg."')";
$res=mysqli_query($con,$sql);
}
if(isset($_POST['btnDisp'])){
header("Location:./disp.php");
}
if(isset($_GET['act'])){

$sql="select * from tblPerson where pid =".$_GET['id'];
$res=mysqli_query($con,$sql);
$row=mysqli_fetch_array($res);
$hobby=explode(",",$row['hobbies']);
$desg=$row['designation'];
}
if(isset($_POST['btnUpd'])){
echo 'upd';
$name=$_POST['txtnm'];
$gen=$_POST['rdbgen'];
$cno=$_POST['txtcno'];
$addr=$_POST['txtaddr'];
$h=$_POST['chk'];
$desg=$_POST['selDesg'];
$hobby=implode(",",$h);
$sql="update tblPerson set pname='".$name."',gender='".$gen."',contactNo='".$cno."',hobbies='".$hobby."',address='".$addr."',designation='".$desg."' where pid=".$_GET['id'];
$res=mysqli_query($con,$sql);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post">
<table width="779" border="1" cellspacing="0" cellpadding="10">
  <tr>
    <th scope="row">Name :</th>
    <td><input type="text" name="txtnm" id="txtnm" value="<?php (isset($row))? print($row[1]):print("") ?>" /></td>
  </tr>
  <tr>
    <th scope="row">Gender :</th>
    <td>
    <?php
if(isset($row)){
if(strcmp($row['gender'],"Male")==0){
    ?>
            <input type="radio" name="rdbgen"  value="Male" checked="checked" />
    Male
           <input type="radio" name="rdbgen"  value="Female" />
                Female
    <?php
}
else{
    ?>
<input type="radio" name="rdbgen"  value="Male" />
      Male
    <input type="radio" name="rdbgen"  value="Female" checked="checked"/>
    Female
<?php
}
}
else{
?>
    <input type="radio" name="rdbgen"  value="Male" />
      Male
    <input type="radio" name="rdbgen"  value="Female"/>
    Female
    <?php
}
    ?>
 
    </td>
  </tr>
  <tr>
    <th scope="row">Contact No. :</th>
    <td><input type="text" name="txtcno" id="txtcno" value="<?php (isset($row))? print($row['contactNo']):print("") ?>" /></td>
  </tr>
  <tr>
    <th scope="row">Address :</th>
    <td><textarea name="txtaddr" id="txtaddr" cols="45" rows="5"><?php (isset($row))? print($row['address']):print("") ?></textarea></td>
  </tr>
  <tr>
    <th scope="row">Hobbies :</th>
    <td>
    <?php
$hb=array("Dancing","Sports","Singing");
if(isset($row)){
$j=0;
foreach($hb as $val){
if(strcmp($hobby[$j],$val)==0){
echo "<input type='checkbox' name='chk[]' value='".$val."' checked='checked' />".$val."<br/>";
$j++;
}
else{
echo "<input type='checkbox' name='chk[]' value='".$val."' />".$val."<br/>";
}
}
}
else{
foreach($hb as $val){
echo "<input type='checkbox' name='chk[]' value='".$val."' />".$val."<br/>";
}
}
?>
      </td>
  </tr>
  <tr>
    <th scope="row">Designation :</th>
    <td><select name="selDesg">
    <?php
$ch=array('Programmer','Project Manager','Analyst','Clerk');
foreach($ch as $c){
if(isset($row) && strcmp($c,$desg)==0){
?>
    <option value="<?php echo $c; ?>" selected="selected"><?php echo $c; ?></option>
   <?php
}
else{
?>
<option value="<?php echo $c; ?>"><?php echo $c; ?></option>
<?php
}
}
?>
    </select></td>
  </tr>
  <tr>
    <th colspan="2" scope="row"><input type="submit" name="<?php (isset($row))? print("btnUpd"):print("btnReg")?>" value="<?php (isset($row))? print("Update"):print("Register Me") ?>" />
    <input type="submit" name="btnDisp" value="Display" />
    </th>
  </tr>
</table>
</form>
</body>
</html> 

Friday, November 9, 2018

Bad words Detection in Input PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post">
<table width="779" border="1" cellspacing="0" cellpadding="10">
  <tr>
    <th scope="row">Enter String :</th>
    <td><textarea name="txtstr" id="txtstr"></textarea></td>
  </tr>
  <tr>
    <th colspan="2" scope="row"><input type="submit" name="btnsubmit" id="btnsubmit" value="Submit" /></th>
  </tr>
</table>
</form>
</body>
</html>
<?php
$wrds=array('oh','allas','wah','omg');
if(isset($_POST['btnsubmit'])){
$str=$_POST['txtstr'];
$a=explode("\n",$str);
foreach($a as $val){
$arr=explode(" ",$val);
foreach($arr as $m){
foreach($wrds as $w){
if(strcmp($w,$m)==0){ echo 'contains bad words.'; exit;
}
}
}
}
}
?>

Saturday, June 4, 2016

WAP to implement Double Ended Restricted Queue

#include<stdio.h>
#include<conio.h>
int dq[5],r=-1,f=-1,r2=5,f2=5,max=5;
void insertr(int x)
{
if(r==max-1)
{
printf("Queue is full");
return;
}
r++;
dq[r]=x;
if(f==-1)
f=0;
r2=f;
f2=r;
}
int deletel()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=dq[f];
if(f==r)
{
f=r=-1;
f2=r2=max;
}
else
{
f++;
f2=r;
r2=f;
}
return x;
}
}
void insertl(int x)
{
if(r2==0)
{
printf("Queue is full");
return;
}
r2--;
dq[r2]=x;
if(f2==max)
f2=max-1;
r=f2;
f=r2;
}
int deleter()
{
int x;
if(f2==max)
{
printf("Queue is empty");
}
else
{
x=dq[f2];
if(f2==r2)
{
f=r=-1;
f2=r2=max;
}
else
{
f2--;
f=r2;
r=f2;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("\nQueue is empty");
return;
}
printf("\n Values in queue are:\n");
for(i=f;i<=r;i++)
{
printf("|%d| ",dq[i]);
}
}
void main()
{
int n,x,res,typ;
clrscr();
printf("\n1. Input restricted");
printf("\n2.Output Restricted");
printf("\nEnter restriction type:");
scanf("%d",&res);
switch(res)
{
case 1:
printf("\n1. Restrict Right Side");
printf("\n2. Restrict Left Side");
printf("\nEnter your Choice: ");
scanf("%d",&typ);
switch(typ)
{
case 1:
do
{
printf("\n1.Insert form Left ");
printf("\n2.Delete from left ");
printf("\n3.Delete form Right");
printf("\n4.display ");
printf("\n5.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertl(x);
break;
case 2:
x=deletel();
printf("\n Deleted value is %d",x);
break;
case 3:
x=deleter();
printf("\n Deleted value is %d",x);
break;
case 4:
display();
break;
case 5:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=5);
break;
case 2:
do
{
printf("\n1.Insert form Right ");
printf("\n2.Delete from left ");
printf("\n3.Delete form Right ");
printf("\n4.display ");
printf("\n5.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertr(x);
break;
case 2:
x=deletel();
printf("\n Deleted value is %d",x);
break;
case 3:
x=deleter();
printf("\n Deleted value is %d",x);
break;
case 4:
display();
break;
case 5:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=5);
break;

}
break;
case 2:
printf("\n1. Restrict Right side");
printf("\n2. Restrict Left Side");
printf("\nEnter your Choice: ");
scanf("%d",&typ);
switch(typ)
{
case 1:
do
{
printf("\n1.Insert form Right ");
printf("\n2.Insert form Left ");
printf("\n3.Delete from left ");
printf("\n4.display ");
printf("\n5.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertr(x);
break;
case 2:
printf("\nEnter value :");
scanf("%d",&x);
insertl(x);
break;
case 3:
x=deletel();
printf("\n Deleted value is %d",x);
break;
case 4:
display();
break;
case 5:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=5);
break;
case 2:
do
{
printf("\n1.Insert form Right ");
printf("\n2.Insert form Left ");
printf("\n3.Delete form Right ");
printf("\n4.display ");
printf("\n5.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertr(x);
break;
case 2:
printf("\nEnter value :");
scanf("%d",&x);
insertl(x);
break;
case 3:
x=deleter();
printf("\n Deleted value is %d",x);
break;
case 4:
display();
break;
case 5:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=5);
break;

}
break;
}
getch();
}

Friday, June 3, 2016

WAP to implement Double Ended Queue

 #include<stdio.h>
#include<conio.h>
int dq[5],r=-1,f=-1,r2=5,f2=5,max=5;
void insertr(int x)
{
if(r==max-1)
{
printf("Queue is full");
return;
}
r++;
dq[r]=x;
if(f==-1)
f=0;
r2=f;
f2=r;
}
int deletel()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=dq[f];
if(f==r)
{
f=r=-1;
f2=r2=max;
}
else
{
f++;
f2=r;
r2=f;
}
return x;
}
}
void insertl(int x)
{
if(r2==0)
{
printf("Queue is full");
return;
}
r2--;
dq[r2]=x;
if(f2==max)
f2=max-1;
r=f2;
f=r2;
}
int deleter()
{
int x;
if(f2==max)
{
printf("Queue is empty");
}
else
{
x=dq[f2];
if(f2==r2)
{
f=r=-1;
f2=r2=max;
}
else
{
f2--;
f=r2;
r=f2;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("\nQueue is empty");
return;
}
printf("\n Values in queue are:\n");
for(i=f;i<=r;i++)
{
printf("|%d| ",dq[i]);
}
}
void main()
{
int n,x;
clrscr();
do
{
printf("\n1.Insert form Right ");
printf("\n2.Insert form Left ");
printf("\n3.Delete from left ");
printf("\n4.Delete form Right ");
printf("\n5.display ");
printf("\n6.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertr(x);
break;
case 2:
printf("\nEnter value :");
scanf("%d",&x);
insertl(x);
break;
case 3:
x=deletel();
printf("\n Deleted value is %d",x);
break;
case 4:
x=deleter();
printf("\n Deleted value is %d",x);
break;
case 5:
display();
break;
case 6:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=6);
getch();
}

Thursday, June 2, 2016

WAP to implement Circular Queue

#include<stdio.h>
#include<conio.h>
int cq[5],r=-1,f=-1,max=4;
void insert(int x)
{
if((r==max && f==0) || f==r+1)
{
printf("Queue is full");
return;
}
if(r==max)
r=0;
else
r++;
cq[r]=x;
if(f==-1)
f=0;
}
int del()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=cq[f];
if(f==r)
{
f=-1;
r=-1;
}
else
{
if(f==max)
f=0;
else
f++;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("Queue is empty");
return;
}
printf("\n Values in queue are:\n");
if(f<=r)
{
for(i=f;i<=r;i++)
{
printf("|%d| ",cq[i]);
}
}
else
{
for(i=f;i<=max;i++)
{
printf("|%d| ",cq[i]);
}
for(i=0;i<=r;i++)
{
printf("|%d| ",cq[i]);
}
}
}
void main()
{
int n,x;
clrscr();
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insert(x);
break;
case 2:
x=del();
printf("\n Deleted value is %d",x);
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=4);
getch();
}

Wednesday, June 1, 2016

WAP to implement Queue of strings

#include<stdio.h>
#include<conio.h>
#include<string.h>
int r=-1,f=-1;
char sq[5][50];
void insert(char s[])
{
if(r==4)
{
printf("Queue is full");
return;
}
r++;
strcpy(sq[r],s);
if(f==-1)
f=0;
}
char* del()
{
char *x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
strcpy(x,sq[f]);
if(f==r)
{
f=-1;
r=-1;
}
else
{
f++;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("Queue is empty");
return;
}
printf("\n Values in queue are:");
for(i=f;i<=r;i++)
{
printf("| %s | ",sq[i]);
}
}
void main()
{
int n,x;
char s[50];
clrscr();
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter string :");
scanf("%s",s);
insert(s);
break;
case 2:
//*st=del();
printf("\n Deleted value is %s",del());
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=4);
getch();
}

Tuesday, May 31, 2016

WAP to implement Queue

#include<stdio.h>
#include<conio.h>
int q[5],r=-1,f=-1;
void insert(int x)
{
if(r==4)
{
printf("Queue is full");
return;
}
r++;
q[r]=x;
if(f==-1)
f=0;
}
int del()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=q[f];
if(f==r)
{
f=-1;
r=-1;
}
else
{
f++;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("No elements in Queue");
return;
}
printf("\n Values in queue are:\n");
for(i=f;i<=r;i++)
{
printf("|%d| ",q[i]);
}
}
void main()
{
int n,x;
clrscr();
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insert(x);
break;
case 2:
x=del();
printf("\n Deleted value is %d",x);
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=4);
getch();
}

Monday, May 30, 2016

WAP to implement stack of strings

#include<stdio.h>
#include<conio.h>
#include<string.h>
int top=-1;
char st[10][50];
void push(char v[])
{
if(top==10)
printf("Stack is full");
else
{
top++;
strcpy(st[top],v);
}

}
char* pop()
{
char *s;
if(top==-1)
printf("\nstack is empty");
else
{
strcpy(s,st[top]);
top--;
}
return s;
}
void peep(int n)
{
if(n>top)
{
printf("Out of Range");
}
else
{
printf("Value at ps %d is %s",n,st[top-n+1]);
}
}
void change(int p,char v[])
{
if(p>top)
{
printf("Out of Range");
}
else
{
strcpy(st[top-p+1],v);
}
}
void display()
{
int i;
if(top==-1)
{
printf("Stack is empty");
return;
}
printf("\n displaying stack:");
for(i=top;i>=0;i--)
{
printf("\n%s",st[i]);
}
}
void main()
{
int n,p;
char v[50];
clrscr();
do
{
printf("\n1.Push\n ");
printf("2.Pop\n ");
printf("3.Peep\n ");
printf("4.Change\n ");
printf("5.Display\n ");
printf("6.Exit\n ");
printf("\nEnter your choice : ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nenter a value :");
scanf("%s",&v);
push(v);
break;
case 2:
printf("Deleted value is: %s",pop());
break;
case 3:
printf("\nenter a positon :");
scanf("%d",&p);
peep(p);
break;
case 4:
printf("\nenter a postion :");
scanf("%d",&p);
printf("\nenter a value :");
scanf("%s",&v);
change(p,v);
break;
case 5:
display();
break;
case 6:
printf("\nThank you");
break;
default:
printf("\nYou have entered a wrong value");
}
}while(n!=6);
getch();
}

Sunday, May 29, 2016

WAP to implement stack with all its operations(push, pop, peep, change, display)

#include<stdio.h>
#include<conio.h>
int top=-1;
int st[10];
void push(int n)
{
if(top==10)
printf("Stack is full");
else
{
top++;
st[top]=n;
}

}
int pop()
{
int x;
if(top==-1)
printf("\nstack is empty");
else
{
x=st[top];
top--;
}
return x;
}
void peep(int n)
{
if(n>top)
{
printf("Out of Range");
}
else
{
printf("Value at ps %d is %d",n,st[top-n+1]);
}
}
void change(int p,int v)
{
if(p>top)
{
printf("Out of Range");
}
else
{
st[top-p+1]=v;
}
}
void display()
{
int i;
if(top==-1)
{
printf("Stack is empty");
return;
}
printf("\n displaying stack:");
for(i=top;i>=0;i--)
{
printf("\n%d",st[i]);
}
}
void main()
{
int n,v,p;
clrscr();
do
{
printf("\n1.Push\n ");
printf("2.Pop\n ");
printf("3.Peep\n ");
printf("4.Change\n ");
printf("5.Display\n ");
printf("6.Exit\n ");
printf("\nEnter your choice : ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nenter a value :");
scanf("%d",&v);
push(v);
break;
case 2:
v=pop();
printf("delete number is: %d",v);
break;
case 3:
printf("\nenter a positon :");
scanf("%d",&p);
peep(p);
break;
case 4:
printf("\nenter a postion :");
scanf("%d",&p);
printf("\nenter a value :");
scanf("%d",&v);
change(v,p);
break;
case 5:
display();
break;
case 6:
printf("\nThank you");
break;
default:
printf("\nYou have entered a wrong value");
}
}while(n!=6);
getch();
}

Saturday, May 28, 2016

WAP to combine two sorted link list using merge sort

#include<stdio.h>
#include<conio.h>
struct node
{
int n;
struct node *next;
}*first=NULL,*first2=NULL,*first3=NULL,*temp,*temp1,*temp2,*temp3;
void insert(int x)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->n=x;
if(first==NULL)
{
temp->next=NULL;
first=temp;
}
else
{
temp1=first;
while(temp1->next->n<x && temp1->next!=NULL)
{
temp1=temp1->next;
}
if(temp1==first && temp1->n>x)
{
temp->next=first;
first=temp;
}
else
{
temp->next=temp1->next;
temp1->next=temp;
}
}
}
void insert2(int x)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->n=x;
if(first2==NULL)
{
temp->next=NULL;
first2=temp;
}
else
{
temp1=first2;
while(temp1->next->n<x && temp1->next!=NULL)
{
temp1=temp1->next;
}
if(temp1==first2 && temp1->n>x)
{
temp->next=first2;
first2=temp;
}
else
{
temp->next=temp1->next;
temp1->next=temp;
}
}
}
void display()
{
if(first==NULL)
{
printf("Stack is empty");
return;
}
temp=first;
while(temp!=NULL)
{
printf("\n%d",temp->n);
temp=temp->next;
}
}
void display2()
{
if(first2==NULL)
{
printf("Stack is empty");
return;
}
temp=first2;
while(temp!=NULL)
{
printf("\n%d",temp->n);
temp=temp->next;
}
}
void display3()
{
if(first3==NULL)
{
printf("Stack is empty");
return;
}
temp=first3;
while(temp!=NULL)
{
printf("\n%d",temp->n);
temp=temp->next;
}
}
void merge()
{
temp2=first;
temp3=first2;
while(temp2!=NULL && temp3!=NULL)
{
temp=(struct node*)malloc(sizeof(struct node));
if(temp2->n<temp3->n)
{
temp->n=temp2->n;
temp2=temp2->next;
}
else
{
temp->n=temp3->n;
temp3=temp3->next;
}
if(first3==NULL)
{
first3=temp;
}
else
{
temp1->next=temp;
}
temp1=temp;
temp->next=NULL;
}
while(temp2!=NULL)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->n=temp2->n;
temp2=temp2->next;
temp1->next=temp;
temp1=temp;
temp->next=NULL;
}
while(temp3!=NULL)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->n=temp3->n;
temp3=temp3->next;
temp1->next=temp;
temp1=temp;
temp->next=NULL;
}
}
void main()
{
int x;
char ch;
clrscr();
printf("\nEnter elements in list 1:\n");
do
{
printf("\nEnter a value: ");
scanf("%d",&x);
insert(x);
fflush(stdin);
display();
printf("\nDo you want to contiune(Y/N):");
scanf("%c",&ch);

}while(ch=='y' || ch=='Y');
printf("\nElements in list 1:\n");
display();
printf("\nEnter elements in list 2:\n");
do
{
printf("\nEnter a value: ");
scanf("%d",&x);
insert2(x);
fflush(stdin);
display2();
printf("\nDo you want to contiune(Y/N):");
scanf("%c",&ch);

}while(ch=='y' || ch=='Y');
printf("\nElements in list 2:\n");
display2();
merge();
printf("\nList after applying merge sort:\n")
display3();
getch();
}

Friday, May 27, 2016

WAP to Implement Merge sort

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,a[5],b[5],c[10],max=5,t;
clrscr();
printf("Enter list in sorted order:");
printf("\nEnter value in list 1:\n");
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&a[i]);
}
printf("\nEnter value in list 2:\n");
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&b[i]);
}
i=0;
j=0;
k=0;
while(i<max && j<max)
{
if(a[i]<b[j])
{
c[k]=a[i];
i++;
}
else
{
c[k]=b[j];
j++;
}
k++;
}
while(i<max)
{
c[k]=a[i];
k++;
i++;
}
while(j<max)
{
c[k]=b[j];
k++;
j++;
}
for(i=0;i<k;i++)
{
printf("\n%d",c[i]);
}
getch();
}

Thursday, May 26, 2016

WAP to implement bubble sort

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10],max=10,t;
clrscr();
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i);
scanf("%d",&a[i]);
}
for(i=0;i<max;i++)
{
for(j=0;j<max-1-i;j++)
{
//printf("\t%d<%d",a[j],a[j+1]);
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
for(i=0;i<max;i++)
{
printf("\n%d",a[i]);
}
getch();
}

Wednesday, May 25, 2016

WAP to implement Insertion sort.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10],max=10,t;
clrscr();
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i);
scanf("%d",&a[i]);
}
for(i=1;i<max;i++)
{
for(j=i-1;j>=0;j--)
{
//printf("\t%d<%d",a[j],a[j+1]);
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
else
break;
}
}
for(i=0;i<max;i++)
{
printf("\n%d",a[i]);
}
getch();
}