Wednesday, 6 June 2012

Interesting facts about MICROSOFT


2)Write the following text into notepad:
“bush hid the facts” save the file and reopen , see the magic!
3)Open MS word and type
=rand(200,99) and press enter then see…
About this 3rd fact ,the whole Microsoft team,even Bill Gates itself does not know why it happen…
1.      We cant create the folders in these name also NUL, COM1 , COM2,.. COM9, LPT1..9 and more…
we can create them by typing the command in cmd prompt C:\> md \\.\c:\con .. See the reason and post, that will more interesting.. and for the third one try the range from =rand(1,1) to =rand(200,99) you will find something.. 

 Microsoft Word allows you to quickly insert sample text into a document. To do this, type =rand() in the document where you want the sample text to appear, and then press ENTER.
You can control how many paragraphs and lines appear by adding numbers inside the parentheses of the rand() function.
The =rand() function has the following syntax:
=rand(paragraph,line) like this =rand(1,2)
up to =rand(201,99) we can give, it’ll display 543 pages. The follwing same para’ll display n times…
On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look. You can easily change the formatting of selected text in the document text by choosing a look for the selected text from the Quick Styles gallery on the Home tab. You can also format text directly by using the other controls on the Home tab. Most controls offer a choice of using the look from the current theme or using a format that you specify directly. To change the overall look of your document, choose new Theme elements on the Page Layout tab. To change the looks available in the Quick Style gallery, use the Change Current Quick Style Set command. Both the Themes gallery and the Quick Styles gallery provide reset commands so that you can always restore the look of your document to the original contained in your current template.
*) other than rand() we can give rand.old(1,2) . It’ll displays
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

*      U cannot create folders with the names con,com1,com2... then LTP1, LPT2..
Because com1,com2 are serial ports
  • LPT1: I/O port usually in monochrome graphics adapters, dedicated IO cards in color systems, or using a controller built into the mainboard
  • LPT2: I/O port usually in serial port controller, or the stand-alone IBM Printer adapter
so we cannot create folders with that names….
If u try , it’ll say ”The specified device name is invalid”
*     

FIFO , LRU


IMPLEMENTATION OF MEMORY MANAGEMENT SCHEME - II (FIFO)
CODING:
#include<stdio.h>
main()
{
int frame[10],p[10],nf,np,avail,i,j,k,count=0;
printf("\nEnter the no of frames:");
scanf("%d",&nf);
printf("\nEnter the no of page numbers:");
scanf("%d",&np);
printf("\nEnter sequence of page numbers:");
for(i=0;i<np;i++)
scanf("%d",&p[i]);
printf("\n");
for(i=0;i<nf;i++)
frame[i]=-1;
j=0;
for(i=0;i<np;i++)
{
avail=0;
for(k=0;k<nf;k++)
{
if(frame[k]==p[i])
avail=1;
}
if(avail==0)
{
frame[j]=p[i];
j=(j+1)%nf;
count++;
for(k=0;k<nf;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("\nNo of page faults:%d",count);
}

OUTPUT:
Enter the no of frames:3
Enter the no of page numbers:11
Enter sequence of page numbers:7
0
1
2
0
3
0
4
2
3
0

7
7
7
2

-1
0
0
0

2
2
4
4
4
0

3
3
3
2
2
2

No of page faults:10

-1
-1
1
1

1
0
0
0
3
3

IMPLEMENTATION OF MEMORY MANAGEMENT SCHEME - II (LRU)
CODING:
#include<stdio.h>
main()
{
int frame[10],frsize,nf,np,count=0,fs[10],flag1,flag2,index,p[10],i,j,k,l,avail,i1;
printf("\nEnter the no of page frames:");
scanf("%d",&nf);
frsize=nf;
printf("\nEnter no of page nos:");
scanf("%d",&np);
printf("\nEnter sequnce of page nos:");
for(i=0;i<np;i++)
scanf("%d",&p[i]);
printf("\n");
for(i=0;i<3;i++)
frame[i]=-1;
for(j=0;j<np;j++)
{
flag1=flag2=0;
for(i=0;i<nf;i++)
{
if(frame[i]==p[j])
{
flag1=flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<nf;i++)
{
if(frame[i]==-1)
{
frame[i]=p[j];
flag2=1;
break;
}

}count++;
}
if(flag2==0)
{
for(i=0;i<nf;i++)
fs[i]=0;
for(k=j-1,l=1;l<=frsize-1;l++,k--)
{
for(i=0;i<nf;i++)
{
if(frame[i]==p[k])
fs[i]=1;
}
}

for(i=0;i<nf;i++)
{
if(fs[i]==0)
index=i;
}
frame[index]=p[j];
}
for(i=0;i<nf;i++)
printf("%d\t",frame[i]);
printf("\n");
}
printf("\nNo of page faults:%d",count);
}

OUTPUT:
Enter the no of page frames:3

Enter no of page nos:8

Enter sequnce of page nos:7
0
1
2
0
3
0
4

7
7
7
2
2
2
2
4

-1
0
0
0
0
0
0
0

No of page faults:6

-1
-1
1
1
1
3
3
3

First fit, Best fit , Worst fit


IMPLEMENTATION OF MEMORY MANAGEMENT SCHEME - I

#include<stdio.h>
main()
{
int p[10],np,b[10],nb,ch,c[10],d[10],alloc[10],flag[10],i,j;
printf("\nEnter the no of process:");
scanf("%d",&np);
printf("\nEnter the no of blocks:");
scanf("%d",&nb);
printf("\nEnter the size of each process:");
for(i=0;i<np;i++)
{
printf("\nProcess %d:",i);
scanf("%d",&p[i]);
}
printf("\nEnter the block sizes:");
for(j=0;j<nb;j++)
{
printf("\nBlock %d:",j);
scanf("%d",&b[j]);c[j]=b[j];d[j]=b[j];
}
if(np<=nb)
{
printf("\n1.First fit 2.Best fit 3.Worst fit");
do
{
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nFirst Fit\n");
for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(p[i]<=b[j])
{
alloc[j]=p[i];printf("\n\nAlloc[%d]",alloc[j]);
printf("\n\nProcess %d of size %d is allocated in block:%d of size:%d",i,p[i],j,b[j]
);
flag[i]=0,b[j]=0;break;
}else flag[i]=1;
}}
for(i=0;i<np;i++)
{
if(flag[i]!=0)
printf("\n\nProcess %d of size %d is not allocated",i,p[i]);
}break;

case 2: printf("\nBest Fit\n");
for(i=0;i<nb;i++)
{
for(j=i+1;j<nb;j++)
{
if(c[i]>c[j])
{
int temp=c[i];c[i]=c[j];c[j]=temp;
}}}
printf("\nAfter sorting block sizes:");
for(i=0;i<nb;i++)
printf("\nBlock %d:%d",i,c[i]);
for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(p[i]<=c[j])
{
alloc[j]=p[i];printf("\n\nAlloc[%d]",alloc[j]);
printf("\n\nProcess %d of size %d is allocated in block %d of size %d",i,p[i],j,c[j]
);
flag[i]=0,c[j]=0;break;
}else flag[i]=1;
}}
for(i=0;i<np;i++)
{
if(flag[i]!=0)
printf("\n\nProcess %d of size %d is not allocated",i,p[i]);
}
break;
case 3: printf("\nWorst Fit\n");
for(i=0;i<nb;i++)
{
for(j=i+1;j<nb;j++)
{
if(d[i]<d[j])
{
int temp=d[i];d[i]=d[j];d[j]=temp;
}}}
printf("\nAfter sorting block sizes:");
for(i=0;i<nb;i++)
printf("\nBlock %d:%d",i,d[i]);
for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(p[i]<=d[j])
{

alloc[j]=p[i];printf("\n\nAlloc[%d]",alloc[j]);
printf("\n\nProcess %d of size %d is allocated in block %d of size %d",i,p[i],j,d[j]

flag[i]=0,d[j]=0;break;
}else flag[i]=1;
}}
for(i=0;i<np;i++)
{
if(flag[i]!=0)
printf("\n\nProcess %d of size %d is not allocated",i,p[i]);
}

break;
default:printf(“Invalid Choice…!”);break;
}
}while(ch<=3);
}}

Output
Enter the no of process:3
Enter the no of blocks:3

Enter the size of each process:
Process 0:100
Process 1:150
Process 2:200

Enter the block sizes:
Block 0:300
Block 1:350
Block 2:200

1.First fit 2.Best fit 3.Worst fit
Enter your choice:1

Alloc[100]
Process 0 of size 100 is allocated in block 0 of size 300

Alloc[150]
Process 1 of size 150 is allocated in block 1 of size 350

Alloc[200]
Process 2 of size 200 is allocated in block 2 of size 200

Enter your choice:2
Best Fit

After sorting block sizes are:
Block 0:200
Block 1:300
Block 2:350

Alloc[100]
Process 0 of size 100 is allocated in block:0 of size:200

Alloc[150]
Process 1 of size 150 is allocated in block:1 of size:300

Alloc[200]
Process 2 of size 200 is allocated in block:2 of size:350

enter your choice:3
Worst Fit

After sorting block sizes are:
Block 0:350
Block 1:300
Block 2:200

Alloc[100]
Process 0 of size 100 is allocated in block 0 of size 350

Alloc[150]
Process 1 of size 150 is allocated in block 1 of size 300

Alloc[200]
Process 2 of size 200 is allocated in block 2 of size 200

Enter your choice:6
Invalid Choice…!


IMPLEMENTATION OF FCFS,SJF,PRIORITY SCHEDULING


//IMPLEMENTATION OF FCFS SCHEDULING
#include<stdio.h>
#include<malloc.h>
struct node
{
char name[15];
int btime,atime;
struct node *next;
};
int main()
{
struct node *head,*temp,*tp,*p;
int d,ch,n=0;
head=NULL;
do
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the name of the process:");
scanf("%s",&temp->name);
printf("\nEnter the arrival time:");
scanf("%d",&temp->atime);
printf("\nEnter the burst time:");
scanf("%d",&temp->btime);
temp->next=NULL;
if(temp==NULL)
printf("\nNode is not created..");
if(head==NULL)
head=temp;
else
{
if(temp->atime<head->atime)
{
temp->next=head;//swapping head and temp
head=temp;
}
else if(temp->atime>head->atime)
{
tp=head;
while((tp!=NULL) && (temp->atime>tp->atime))
{

p=tp;
tp=tp->next;
}
p->next=temp;
temp->next=tp;
}
}
printf("\nPress '1' to continue:");
scanf("%d",&ch);
}while(ch==1);
printf("\nGantt chart:");
if(head==NULL)
printf("\nList is empty...! ");
else
{
tp=head;
printf("\n");
printf("\t%s",tp->name);
tp=tp->next;
while(tp!=NULL)
{
printf("\t%s",tp->name);
tp=tp->next;
}
printf("\t%s",tp->name);
printf("\n");
tp=head;
printf("\n");
printf("0");
while(tp->next!=NULL)
{
n=n+tp->btime;
printf("\t%d",n);
tp=tp->next;
}
n=n+tp->btime;
printf("\t%d",n);
}
}

OUTPUT:
Enter the name of the process:P1
Enter the arrival time:0
Enter the burst time:4
Press '1' to continue:1
Enter the name of the process:P2
Enter the arrival time:3
Enter the burst time:1
Press '1' to continue:1
Enter the name of the process:P3
Enter the arrival time:4
Enter the burst time:2
Press '1' to continue:1
Enter the name of the process:P4
Enter the arrival time:6
Enter the burst time:3
Press '1' to continue:1
Enter the name of the process:P5
Enter the arrival time:8
Enter the burst time:2
Press '1' to continue:0

Gantt chart:
P1 P2
0
4
5

P3
7

P4
10

P5
12

// IMPLEMENTATION OF SJF SCHEDULING
#include<stdio.h>
#include<malloc.h>
struct node
{
char name[15];
int btime,atime;
struct node *next;
};
int main()
{
struct node *head,*temp,*tp,*p;
int d,ch,n=0;
head=NULL;
do
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the name of the process:");
scanf("%s",&temp->name);
printf("\nEnter the burst time:");
scanf("%d",&temp->btime);
temp->next=NULL;
if(temp==NULL)
printf("\nNode is not created..");
if(head==NULL)
head=temp;
else
{
if(temp->btime<head->btime)
{
temp->next=head;//swapping head and temp
head=temp;
}
}
if(temp->btime>head->btime)
{
tp=head;
while((tp!=NULL) && (temp->btime>tp->btime))
{
p=tp;

tp=tp->next;
}
p->next=temp;
temp->next=tp;
}
printf("\nPress '1' to continue:");
scanf("%d",&ch);
}while(ch==1);
printf("\nGantt chart:");
if(head==NULL)
printf("\nList is empty...! ");
else
{
tp=head;
printf("\n");
printf("\t%s",tp->name);
tp=tp->next;
while(tp!=NULL)
{
printf("\t%s",tp->name);
tp=tp->next;
}
printf("\t%s",tp->name);
printf("\n");
tp=head;
printf("\n");
printf("0");
while(tp->next!=NULL)
{
n=n+tp->btime;
printf("\t%d",n);
tp=tp->next;
}
n=n+tp->btime;
printf("\t%d",n);
}
}

OUTPUT:
Enter the name of the process:P1
Enter the burst time:5
Press '1' to continue:1
Enter the name of the process:P2
Enter the burst time:9
Press '1' to continue:1
Enter the name of the process:P3
Enter the burst time:2
Press '1' to continue:1
Enter the name of the process:P4
Enter the burst time:6
Press '1' to continue:1
Enter the name of the process:P5
Enter the burst time:12
Press '1' to continue:0

Gantt chart:
P3 P1
0
2
7

P4
13

P2
22

P5
34

//IMPLEMENTATION OF PRIORITY SCHEDULING
#include<stdio.h>
#include<malloc.h>
struct node
{
char name[15];
int btime,priority;
struct node *next;
};
int main()
{
struct node *head,*temp,*tp,*p;
int d,ch,n=0;
head=NULL;
do
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the name of the process:");
scanf("%s",&temp->name);
printf("\nEnter the priority:");
scanf("%d",&temp-> priority);
printf("\nEnter the burst time:");
scanf("%d",&temp->btime);
temp->next=NULL;
if(temp==NULL)
printf("\nNode is not created..");
if(head==NULL)
head=temp;
else
{
if(temp-> priority <head-> priority)
{
temp->next=head;//swapping head and temp
head=temp;
}
else if(temp-> priority >head-> priority)
{
tp=head;
while((tp!=NULL) && (temp-> priority >tp-> priority))
{

p=tp;
tp=tp->next;
}
p->next=temp;
temp->next=tp;
}
}
printf("\nPress '1' to continue:");
scanf("%d",&ch);
}while(ch==1);
printf("\nGantt chart:");
if(head==NULL)
printf("\nList is empty...! ");
else
{
tp=head;
printf("\n");
printf("\t%s",tp->name);
tp=tp->next;
while(tp!=NULL)
{
printf("\t%s",tp->name);
tp=tp->next;
}
printf("\t%s",tp->name);
printf("\n");
tp=head;
printf("\n");
printf("0");
while(tp->next!=NULL)
{
n=n+tp->btime;
printf("\t%d",n);
tp=tp->next;
}
n=n+tp->btime;
printf("\t%d",n);
}
}

OUTPUT:
Enter the name of the process:P1
Enter the priority:7
Enter the burst time:5
Press '1' to continue:1
Enter the name of the process:P2
Enter the priority:4
Enter the burst time:2
Press '1' to continue:1
Enter the name of the process:P3
Enter the priority:0
Enter the burst time:10
Press '1' to continue:1

Gantt chart:
P3
P2
0
10
12

P1
17

(null)

FILE MANIPULATIONS


#include<stdio.h>
#include<sys/stat.h>
#include<fcntl.h>
int main()
{
struct stat stbuf;
char file[10],old[20],new[20],filename[20];
int amode,ch;
printf("\n1.Rename 2.Remove 3.Change access 4.Display access mode");
do
{
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nEnter file to rename:");
scanf("%s",old);
printf("\nEnter the new name:");
scanf("%s",new);
if(rename(old,new)==0)
printf("\n%s is renamed as %s",old,new);
else
printf("\nError in renaming %s",old); break;
case 2:printf("Enter filename to be removed:");
scanf("%s",file);
if(remove(file)==0)
printf("\n%s is removed",file);
else
printf("\nError in removing %s",file); break;
case 3:printf("\nEnter the name of the file to change its access mode:");
scanf("%s",filename);
if((stat(filename,&stbuf))!=0)
{
printf("\nError in moving status info of %s to the strct variable
stbuf..",filename); break;
}
if(stbuf.st_mode & S_IWRITE)
{
printf("\n%s is Changed to READ ACCESS ONLY",filename);
amode=S_IREAD;
}
else
{
printf("\n%s is Changed to WRITE ACCESS ONLY",filename);
amode=S_IWRITE;

}
if(chmod(filename,amode)!=0)
{
printf("\nError in changing the access mode...!");
break;
} break;
case 4:printf("\nCheck the access mode:READ/WRITE mode:");
printf("\nEnter name of a file:");
scanf("%s",filename);
if((access(filename,R_OK))==0)
printf("\n%s has READ permission only..",filename);
if((access(filename,W_OK))==0)
printf("\n%s has WRITE permission only..",filename);
else
printf("\n%s does not have read/write permission");
break;
default:printf("\nInvalid choice...!"); break;
}
}while(ch<=4);
}

OUTPUT

1.Rename 2.Remove 3.Change access 4.Display access mode
Enter your choice:1
Enter file to rename:sum.sh
Enter the new name:add.sh
sum.sh is renamed as add.sh
Enter your choice:2
Enter filename to be removed:add.sh
add.sh is removed
Enter your choice:3
Enter the name of the file to change its access mode:first.c
first.c is Changed to READ ACCESS ONLY
Enter your choice:4
Check the access mode:READ/WRITE mode:
Enter name of a file:first.c
first.c has READ permission only..
Enter your choice:5
Invalid choice…!