New Android apps UniqueKey

Tuesday, 12 May 2015

VB Script : Fun Program

This is a fun VB Script program. if someone run this program in his pc then it will never end until you finish it from task manager in pc. this is for simple prank. have fun..


Write this program in notepad and save it as _filename.vbs 

DO
msgbox("manoj")
LOOP

VB Script : Simple Program



Write this program in notepad and save it as _filename.vbs 
pass=inputbox("password")

if pass="manoj" then msgbox("correct password")
 else msgbox("password is not correct  try again")

Clock using Notepad


@echo off
:start
echo date:%date% time:%time%
goto start

Wednesday, 6 May 2015

FIFO, SJF, Priority Scheduling, Round Robin Scheduling Algorithms

Scheduling algorithms are very important concept in operating system to decide which process has to allocate CPU next. there are many types of Scheduling algorithms e.g. FIFO (first in first out), SJF (Shortest job first), Priority scheduling, RR (round robin), Multilevel queue, Multilevel feedback queue. 
following program describes FIFO, SJF, RR and Priority scheduling algorithms.

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

struct templet
{
    char name[8];
    int at,st,pt,ft,tat,wt,priority,remain,flag;
}p[20],temp;


int n,Bu[20],Twt,Ttt,A[10],Wt[10],w,wait[50],turn[50];
float Awt,Att;
char pname[20][20],c[20][20];

void Getdata();
void Gantt_chart();
void Calculate();
void chart();
void fcfs();
void sjf();
void rr();
void prio();
//srand(time(NULL));
int main()
{
    int ch;
    do{
    printf("\n1.FCFS\n2.SJF\n3.Round Robin\n4.Priority\n5.exit");
    printf("\nEnter choice : ");
    scanf("%d",&ch);
    switch(ch)
    {
        case 1: Getdata();
          fcfs();
                break;
        case 2:sjf();
                break;
        case 3: rr();
                break;
        case 4: prio();
                break;
    }}while(ch!=5);
}
void fcfs()
{
 int i,j,temp, temp1;
 Twt=0;
 Ttt=0;
 printf("\n\n FIRST COME FIRST SERVED ALGORITHM\n");
 for(i=1;i<=n;i++)
 {
  for(j=i+1;j<=n;j++)
  {
   if(A[i]>A[j])
   {
    temp=Bu[i];
    temp1=A[i];
    Bu[i]=Bu[j];
    A[i]=A[j];
    Bu[j]=temp;
    A[j]=temp1;
    strcpy(c[i],pname[i]);
    strcpy(pname[i],pname[j]);
    strcpy(pname[j],c[i]);
   }
  }
 }
 Calculate();
 Gantt_chart();
 chart();
}

void sjf()
{
 srand(time(NULL));
    int no,i,j,fcnt=0,scnt=0;
    printf("\nEnter no of processes : ");
    scanf("%d",&no);
    for(i=0;i<no;i++)
    {
        printf("\n\nEnter process name : ");
        scanf("%s",p[i].name);
        p[i].at=rand()%50;
  printf("\nArrival time is %d ",p[i].at);
        p[i].pt=rand()%50;
        printf("\nEnter Burst time is %d ",p[i].pt);
        
        p[i].remain=p[i].pt;
        p[i].flag=0;
    }
    for(i=0;i<no;i++)
    {
        for(j=0;j<no;j++)
        {
            if(p[i].at<p[j].at)
            {
                temp=p[i];
                p[i]=p[j];
                p[j]=temp;
            }
        }
    }
    printf("\n\t Grant Chart : \n\t\t");
   
    i=0;
    scnt=p[i].at;
    while(1)
    {
        if(p[i].flag==0)
        {
            printf("%s--->",p[i].name);
            p[i].remain--;
            scnt++;
            if(p[i].remain>0)
            {
                for(j=0;j<no;j++)
                {
                    if(p[j].at<=scnt && p[j].flag==0)
                    {
                        if(p[i].remain>p[j].remain)
                        {
                            i=j;
                            printf("- ");
                        }
                    }
                }
            }
            else
            {
                p[i].wt=scnt-p[i].pt-p[i].at;
                p[i].tat=scnt-p[i].at;
                p[i].flag=1;
                fcnt++;
                printf("+");
                if(fcnt==no)
                    break;
                if(i<no-1)
                    i++;
                else
                    i=0;
                for(j=i;j>0;j--)
                        if(p[j].remain < p[i].remain && p[j].flag==0)
                            i=j;
            }
        }
        else
            i++;
    }
   
    printf(" Finish\n");
    fcnt=0,scnt=0;
    printf("\n\tProcess \t burst time \t waiting time \t turn around time");
    for(i=0;i<no;i++)
    {
        printf("\n\t%s\t\t\t%d\t\t%d\t \t%d",p[i].name,p[i].pt,p[i].wt,p[i].tat);
        fcnt+=p[i].wt;
        scnt+=p[i].tat;
    }
    printf("\n-------------------------------------------------------------------");
    printf("\n\n\t\t\t\tAverage : \t %d\t   \t%d",fcnt/no,scnt/no);
}

void rr()
{
 srand(time(NULL));
    int no,i,j,fcnt=0,scnt=0,interval;
    printf("\nEnter no of processes : ");
    scanf("%d",&no);
    for(i=0;i<no;i++)
    {
        printf("\nEnter process name : ");
        scanf("%s",p[i].name);
        //p[i].pt=rand()%50;
  printf("\nenter Burst time : ");
        scanf("%d",&p[i].pt);
        p[i].remain=p[i].pt;
        p[i].flag=0;
    }
    //interval=rand()%10;
 printf("\nenter time quantum : ");
 scanf("%d",&interval);
    
   
    printf("\n\t Grant Chart : \n\t\t");
   
    i=0;
    while(1)
    {
        for(i=0;i<no;i++)
        {
        if(p[i].flag==0)
        {
            if(p[i].remain<=interval)
            {
                printf("-- %s (C)--",p[i].name);
                scnt+=p[i].remain;
                p[i].wt=scnt-p[i].pt;
                p[i].tat=scnt;
                p[i].flag=1;
                fcnt++;
            }
            else
            {
                printf("-- %s --",p[i].name);
                p[i].remain-=interval;
                scnt+=interval;
            }
        }
        }
        if(fcnt==no)
            break;
    }
   
    printf("Finish");
    fcnt=0,scnt=0;
    printf("\n\tProcess \t burst time \t waiting time \t turn around time");
    for(i=0;i<no;i++)
    {
        printf("\n\t%s\t\t\t%d\t\t%d\t \t%d",p[i].name,p[i].pt,p[i].wt,p[i].tat);
        fcnt+=p[i].wt;
        scnt+=p[i].tat;
    }
    printf("\n-----------------------------------------------------------------\n");
    printf("\n\n\t\t\t\tAverage : \t %d\t   \t%d",fcnt/no,scnt/no);
}

void prio()
{
 srand(time(NULL));
    int no,i,j,fcnt=0,scnt=0;
    printf("\nEnter no of processes : ");
    scanf("%d",&no);
    for(i=0;i<no;i++)
    {
        printf("\nEnter process name : ");
        scanf("%s",p[i].name);
        p[i].pt=rand()%50;
  printf("\nBurst time  is %d ",p[i].pt);
        p[i].priority=rand()%10;
        printf("\npriority is %d ",p[i].priority);
        
    }
    for(i=0;i<no;i++)
    {
        for(j=0;j<no;j++)
        {
            if(p[i].priority<p[j].priority)
            {
                temp=p[i];
                p[i]=p[j];
                p[j]=temp;
            }
        }
    }
    printf("\n\t Grant Chart : \n\t\t");
    for(i=0;i<no;i++)
    {
        p[i].st=fcnt;
        fcnt+=p[i].pt;
        p[i].wt=fcnt-p[i].pt;
        p[i].tat=fcnt;
        printf("%s -->",p[i].name);
    }
    printf("Finish");
    fcnt=0;
    printf("\n\tProcess \t burst time \t waiting time \t turn around time");
    for(i=0;i<no;i++)
    {
        printf("\n\t%s\t\t\t%d\t\t%d\t \t%d",p[i].name,p[i].pt,p[i].wt,p[i].tat);
        fcnt+=p[i].wt;
        scnt+=p[i].tat;
    }
    printf("\n\n\t\t\t\tAverage : \t %d\t   \t%d",fcnt/no,scnt/no);
}
void Getdata()
{
 srand(time(0));
 int i;
 printf("\n Enter the number of processes: ");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  fflush(stdin);
  printf("\n Enter the process name: ");
  scanf("%s",&pname[i]);
  Bu[i] = rand()%50;
  printf(" burst time for process %s is %d \n",pname[i],Bu[i]);
  A[i] = rand()%50;
  printf(" Arrival time for process %s is %d \n",pname[i],A[i]);
 }
}

void Gantt_chart()
{
 int i;
 printf("\n\n\t\t\tGANTT CHART\n");
 printf("\n-----------------------------------------------------------\n");
 for(i=1;i<=n;i++)
  printf("|\t%s\t",pname[i]);
 printf("|\t\n");
 printf("\n-----------------------------------------------------------\n");
 printf("\n");
 for(i=1;i<=n;i++)
 printf("%d\t\t",Wt[i]);
 printf("%d",Wt[n]+Bu[n]);
 //turn[i]=Wt[n]+Bu[n];
 printf("\n-----------------------------------------------------------\n");
 printf("\n");
 }

void Calculate()
{
 int i;
 Wt[1]=0;
 wait[1]=0;
 turn[1]=Bu[1];
 for(i=2;i<=n;i++)
 {
  Wt[i]=Bu[i-1]+Wt[i-1];
  wait[i]=Wt[i];
  turn[i]=Wt[i]+Bu[i];
 }
 for(i=1;i<=n;i++)
 {
  Twt=Twt+(Wt[i]-A[i]);
  Ttt=Ttt+((Wt[i]+Bu[i])-A[i]);
 }
 Att=(float)Ttt/n;
 Awt=(float)Twt/n;
 printf("\n\n Average Turn around time=%3.2f ms ",Att); 
 printf("\n\n AverageWaiting Time=%3.2f ms",Awt);
}

void chart(){
 int k;
 printf("name\t burst time\t Arrival time \t Waiting time  turnaround time\n");
 for (k=1;k<=n;k++)
 {
  printf("%s\t   %d\t\t %d\t\t\t %d\t\t%d\n",pname[k],Bu[k],A[k],wait[k],turn[k]);
 }
}

Saturday, 21 March 2015

Simple Linked list Program

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

struct node
{
 int data;
 struct node *link;                 //to creating self reference pointer
};

int display(struct node *,int);
void insertion(struct node *,int);
void deletion(struct node *,int);

struct node *head;
int count=0;

main() 
{
   int i,choice,inst=0,del,chk1=1,chk=1,num;
  
   do
   {
   printf("\nMENU:\n\n 1.Insertion\n 2.Deletion \n 3.Display\n 4.Exit\n\nenter your choice :     ");
   scanf("%d",&choice);
   
   switch(choice)
   {
  case 1:
          if(count==0)
          { 
           printf("\nThis is First Node\n"); 
          head=(struct node *)malloc(sizeof(struct node));
           insertion(head,inst);
          }
         else
         {
           printf("Where do you want to insert data\n 1. In starting \n2. End\n");
           scanf("%d",&inst);
           insertion(head,inst);
         }   
         break;
         
  case 2:
          printf("from where do you want to delete\n 1. In starting 2. End\n");
          scanf("%d",&del);
          deletion(head,del);
          break;
          
  case 3:
         chk1=display(head,count);
         if(chk1==1)
         printf("NULL\n");
         break;
         
  case 4:
          chk=0;
          break;
     
    default : printf("invalid option selected\ntry again\n\n");        
   }
 }
 while(choice!=4);
  }
  
void insertion(struct node *list,int num)
{ 
  struct node *new1;
  int num1;
  
  printf("Enter the number\n");
  scanf("%d",&num1);
  
  if(count==0&&num==0)
  {
    head->data=num1;
 head->link=NULL;
  }
  else if(num==1&&count>0)
  {
 new1=(struct node *)malloc(sizeof(struct node));
 new1->data=num1;
 new1->link=head;
 head=new1;
  }
  else if(num==2&&count>0)
  {
 for( ; ;)
 {
   if(list->link!=NULL)
      list=list->link;
   else
  {
    new1=(struct node *)malloc(sizeof(struct node));
    new1->data=num1;
    list->link=new1;
    new1->link=NULL;
    break;
  }
 }
  }
  
 count++;
 
}

void deletion(struct node *list,int num)
{
  struct node *temp;
  
  if(num==1&&count>0)
 {
   head=list->link;
   free(list);
 }
  else if(num==2&&count>1)
 {
   for( ; ;)
    {
  if(list->link->link!=NULL)
     list=list->link;
  else
   {
     free(list->link);
     list->link=NULL;
   break;
    }
   }
 }
 else if(count==1)
   free(head);
 else if(count<=0)
 {
    printf("List is empty\n\n"); 
    count--; 
 }
 count--;
 
}

int display(struct node *list,int num)
{ 
  int chk=1;
  
  if(num>0)
   {
  printf("%d->",list->data);
  num--;
  display(list->link,num);
   }
  else if(count<=0)
 {
   chk=0;
   printf("list is empty\n\n");
 }
 return(chk);
}