Sunday, October 25, 2015

How do I block a website in all web browsers in Windows7 ?

To block any website, on every browser, you need to edit the hosts file. A hosts file is a local file stored on the computer that translates domain names or NetBIOS names into an IP addresses. For example, in the example below, the line translates 69.72.169.241 into the Computer Hope domain.

Follow the steps bellow..

Step 1: Open the file "hosts" with Notepad.

       Go to Start-->All Programs-->Accessories then run the Notepad as Administrator
Click on File then click Open on left corner of the Notepad and open the Hosts file.
Copy and paste the link bellow directly in File name: C:\Windows\System32\drivers\etc\hostsNow the hosts file is open.

Step 2: Add the website to the host file which you want to block.

       Scroll to the empty space at the bottom of the file. There will be a lot of code and text, but you don't have to touch any of it. Instead, scroll all the way down to the bottom, where the last line should be something resembling "127.0.0.1 localhost". Do not edit or change anything as you're working. This file is essential to internet connections, and all you need to do add a few lines at the bottom to block websites. Start your new line right underneath the last "localhost" line and add the following lines (replacing xxx.com with the site you want to block)
127.0.0.1         www.xxx.com
127.0.0.1         www.yyy.com
       Block websites by writing "127.0.0.1," followed by the website URL. At the beginning of the line, write 127.0.0.1, hit the space bar, and then write out the URL of the website. For example, to block yahoo, you'd write "127.0.0.1 www.yahoo.com." Do not add the "http://" to the website URL, or it will fail to block.

 Step 3: Save the hosts file.

       Click on the File menu and click Save. Close the file. The site should be blocked in all web browsers and now instead of trying to access that site the computer will redirect you to the localhost.

If you like what you read.. share your thoughts in the comment box bellow. |Thanks|

Sunday, October 18, 2015

C Program to implement First In First Out (FIFO) page replacement algorithm.

/* ================================================================================
 *  * *
 *  * *       Filename:  fifo.c
 *  * *        Created:  Tuesday 24 March 2015
 *  * *       Compiler:  gcc
 *  * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 *  * *   Organization:  SCIS,University of Hyderabad
 *  * *
 *  ===============================================================================*/
#include<stdio.h>
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n======================================================");
printf("\nEnter the number of pages:");
scanf("%d",&n);
printf("Enter the page numbers :\n");
for(i=1;i<=n;i++)
scanf("\t %d",&a[i]);
printf("\n======================================================");
printf("\nEnter the number of frames :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= 0;
j=0;
printf("======================================================\n");
printf("Page Number\tPage frames\n");
printf("- - - - - -\t- - - - - -\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("======================================================\n");
printf("Page Fault is: %d",count);
printf("\n======================================================\n");
return 0;
}

C Program to implement Least Recently Used (LRU) page replacement algorithm.

/* ================================================================================
 *  * *
 *  * *       Filename:  lru.c
 *  * *        Created:  Tuesday 24 March 2015
 *  * *       Compiler:  gcc
 *  * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 *  * *   Organization:  SCIS,University of Hyderabad
 *  * *
 *  ===============================================================================*/
#include<stdio.h>
int fr[3];
void main()
{
void display();
int n;
int p[100],t,i,j,fs[3];
printf("======================================================\n");
printf("Enter the number of pages:");
scanf("%d",&n);
printf("Enter the all PAGE number:\n");
for(t=0; t<n; t++)
{
scanf("%d",&p[t]);
}
printf("The PAGE numbers are:\n");
for(t=0; t<n; t++)
{
printf("%d\t",p[t]);
}
printf("\n======================================================\n");
int index,k,l,flag1=0,flag2=0,pf=0,frsize=3;
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<n;j++)
{
flag1=0,flag2=0;
for(i=0;i<3;i++)
{
if(fr[i]==p[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<3;i++)
{
if(fr[i]==-1)
{
fr[i]=p[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
for(i=0;i<3;i++)
fs[i]=0;
for(k=j-1,l=1;l<=frsize-1;l++,k--)
{
for(i=0;i<3;i++)
{
if(fr[i]==p[k])
fs[i]=1;
}
}
for(i=0;i<3;i++)
{
if(fs[i]==0)
index=i;
}
fr[index]=p[j];
pf++;
}
display();
}
printf("\n-----------------------------------------------------\n");
printf("\n\tTotal number of page faults :%d",pf);
printf("\n======================================================\n");
printf("\n");
}
void display()
{
int i;
printf("\n");
for(i=0;i<3;i++)
printf("\t%d",fr[i]);
}

C Program to implement Shortest Seek Time First (SSTF) scheduling algorithm.

/* ================================================================================
 *  * *
 *  * *       Filename:  sstf.c
 *  * *        Created:  Tuesday 24 March 2015
 *  * *       Compiler:  gcc
 *  * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 *  * *   Organization:  SCIS,University of Hyderabad
 *  * *
 *  ===============================================================================*/

#include<stdio.h>
#include<stdlib.h>
void main()
{
int pos,size,diff = 1000,loc,i,j;
printf("========================================================");
printf("\nEnter the current head position:\n");
scanf("%d",&pos);
printf("\nEnter the number of DISK position:\n");
scanf("%d",&size);
int req[size];
printf("========================================================");
printf("\nEnter the location position to schedule:\n");
for(i=0;i<size;i++)
scanf("%d",&req[i]);
printf("========================================================");
printf("\nSSTF requests served in the order as follows :\n");
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(req[j] == -1)
continue;
else
{
if(abs(pos - req[j]) <= diff)
{
diff = abs(pos - req[j]);
loc = j;
}
}
}
diff = 1000;
printf("%d ",req[loc]);
pos = req[loc];
req[loc] = -1;
}
printf("\n========================================================");
printf("\n");
}

C Program to perform arithmatic operation of two large integers on 32 bit machine.

/* ================================================================================
 *  * *
 *  * *       Filename:  op_largenumber.c
 *  * *        Created:  Tuesday 17 February 2015
 *  * *       Compiler:  gcc
 *  * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 *  * *   Organization:  SCIS,University of Hyderabad
 *  * *
 *  ===============================================================================*/

#include <stdio.h>
#include <string.h>
#define MAX 100
void sub(char num1[], char num2[], int n1, int n2);
void add(char num1[], char num2[], int n1, int n2);
char num1[MAX],num2[MAX],res[MAX+1];
void main()
{
char temp[2]="0",temp2[MAX];
int n1,n2,i,j,temp1,c=0,t1,t2,ch;
printf("===================================================================");
printf("\nDecide what do you wanna perform\n");
printf("1.Addition\t2.Subtraction");
printf("\nEnter your choice:");
scanf("%d",&ch);
printf("===================================================================\n");
switch(ch)
{
case 1 :
printf("Enter the first number:");
scanf("%s",num1);
printf("Enter the second number:");
scanf("%s",num2);
n1 = strlen(num1);
n2 = strlen(num2);
add(num1,num2,n1,n2);
break;
case 2 :
printf("Enter the larger number first!");
printf("\nEnter the first number:");
scanf("%s",num1);
printf("Enter the second number:");
scanf("%s",num2);
n1 = strlen(num1);
n2 = strlen(num2);
sub(num1,num2,n1,n2);
break;
default :
printf("Wrong input!!\n");
}
printf("===================================================================");
printf("\n");
}

void add(char num1[], char num2[], int n1,int n2)
{
char temp[2]="0",temp2[MAX];
int i,j,temp1,c=0,t1,t2;

if(n1>n2)
{
for(i=0;i<(n1-n2);i++)
temp2[i]='0';
for(j=i;j<n1;j++)
{
temp2[j]=num2[c];
c++;
}
for(i=0;i<n1;i++)
num2[i]=temp2[i];
n2=n1;
}
else if(n2>n1)
{
for(i=0;i<(n2-n1);i++)
temp2[i]='0';
for(j=i;j<n2;j++)
{
temp2[j]=num1[c];
c++;
}
for(i=0;i<n2;i++)
num1[i]=temp2[i];
n1=n2;
}
for(i=n1-1;i>=0;i--)
{
temp1 = ( num1[i] - 48 + num2[i] - 48 + temp[0] - 48 );
sprintf(temp, "%d", temp1);
if(strlen(temp)==1)
{
res[i+1]=temp[0];
temp[0]='0';
}
else
res[i+1]=temp[1];
}
if(strlen(temp)==2)
res[0] = temp[0];
else
res[0] = '0';

printf("\nThe sum of the above two number is: %s\n",res);
}

void sub(char num1[], char num2[], int n1,int n2)
{
char temp[2]="0",temp2[MAX];
int i,j,temp1,c=0,t1,t2;
if(n1>n2)
{
for(i=0;i<(n1-n2);i++)
temp2[i]='0';
for(j=i;j<n1;j++)
{
temp2[j]=num2[c];
c++;
}
for(i=0;i<n1;i++)
num2[i]=temp2[i];
n2=n1;
}
else if(n2>n1)
{
for(i=0;i<(n2-n1);i++)
temp2[i]='0';
for(j=i;j<n2;j++)
{
temp2[j]=num1[c];
c++;
}
for(i=0;i<n2;i++)
num1[i]=temp2[i];
n1=n2;
}
c = 0;
for(i=n1-1;i>=0;i--)
{
if(c==1)
{
if(num1[i]!='0')
t1 = num1[i] - 48 - 1;
else
t1 = 9;
}
else
{
t1 = num1[i] - 48;
}
t2 = num2[i] - 48;
if((t1 < t2) && i != 0)
{
t1 += 10;
c = 1;
}
else if(t1 > t2)
c = 0;
else if((t1 < t2) && i == 0)
{
t1 = t1 + t2;
t2 = t1 - t2;
t1 = t1 - t2;
c = 1;
}
temp1 = t1 - t2 ;
sprintf(temp, "%d", temp1);
res[i+1] = temp[0];
}
if(c==1)
res[0] = '-';
else
res[0] = '+';

printf("\nThe substraction of the above two number is: %s\n",res);
}

OutPut:

C Program to convert a decimal number in to binary and perform right-shift.

/* =====================================================================================
 * *
 * *       Filename:  rightshift.c
 * *        Created:  Tuesday 3 February 2015
 * *       Compiler:  gcc
 * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 * *   Organization:  SCIS,University of Hyderabad
 * *
 * * =====================================================================================*/

#include<stdio.h>
int main()
{
int dn,rem,quo,k=0,m,sb,temp;
int binaryNumber[100],bin[100],i=1,j;
printf("------------------------------------------\n");
printf("Enter any decimal number: ");
scanf("%d",&dn);
quo = dn;
while(quo!=0)
{
binaryNumber[i++]= quo % 2;
quo = quo / 2;
}
printf("\nEquivalent binary value of decimal number %d: ",dn);
for(j = i -1 ;j> 0;j--)
{
printf("%d",binaryNumber[j]);
bin[k]=binaryNumber[j];
k++;
}
printf("\n------------------------------------------");
printf("\nHow many bits you wanna right-shift:");
scanf("%d",&sb);
for(i=0; i<sb; i++)
{
temp=bin[k-1];
for(m=k-1; m>=0; m--)
{
bin[m]=bin[m-1];
}
bin[0]=temp;
}
printf("\nThe binary number after right-shift:");
for(m=0 ;m<k; m++)
{
printf("%d",bin[m]);
}
printf("\n------------------------------------------\n");
return 0;
}

OutPut:

C Program to convert a decimal number in to binary and perform left-shift.

/* =====================================================================================
 * *
 * *       Filename:  leftshift.c
 * *        Created:  Tuesday 3 February 2015
 * *       Compiler:  gcc
 * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 * *   Organization:  SCIS,University of Hyderabad
 * *
 * * =====================================================================================*/

#include<stdio.h>
int main()
{
int dn,rem,quo,k=0,m,sb,temp;
int binaryNumber[100],bin[100],i=1,j;
printf("------------------------------------------\n");
printf("Enter any decimal number: ");
scanf("%d",&dn);
quo = dn;
while(quo!=0)
{
binaryNumber[i++]= quo % 2;
quo = quo / 2;
}
printf("\nEquivalent binary value of decimal number %d: ",dn);
for(j = i -1 ;j> 0;j--)
{
printf("%d",binaryNumber[j]);
bin[k]=binaryNumber[j];
k++;
}
printf("\n------------------------------------------");
printf("\nHow many bits you wanna left-shift:");
scanf("%d",&sb);
for(i=0; i<sb; i++)
{
temp=bin[0];
for(m=0; m<k; m++)
{
bin[m]=bin[m+1];
}
bin[k-1]=temp;
}
printf("\nThe binary number after left-shift:");
for(m=0 ;m<k; m++)
{
printf("%d",bin[m]);
}
printf("\n------------------------------------------\n");
return 0;
}

OutPut:

C Program to convert a decimal number in to binary and count the number of zeros and ones.

/* =====================================================================================
 * *
 * *       Filename:  bincount.c
 * *        Created:  Tuesday 3 February 2015
 * *       Compiler:  gcc
 * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 * *   Organization:  SCIS,University of Hyderabad
 * *
 * * =====================================================================================*/

#include<stdio.h>
int main()
{
int dn,quo,k=0,m;
int zcount=0,ocount=0;
int binaryNumber[100],bin[100],i=1,j;
printf("------------------------------------------\n");
printf("Enter any decimal number: ");
scanf("%d",&dn);
quo = dn;
while(quo!=0)
{
binaryNumber[i++]= quo % 2;
quo = quo / 2;
}
printf("\nEquivalent binary value of decimal number %d: ",dn);
for(j = i -1 ;j> 0;j--)
{
printf("%d",binaryNumber[j]);
bin[k]=binaryNumber[j];
k++;
}
printf("\n------------------------------------------");
for(m=0 ;m<k; m++)
{
if(bin[m]==0)
{
zcount++;
}
else
{
ocount++;
}
}
printf("\nThe number of ZERO present in the binary number: \t %d\n",zcount);
printf("The number of ONE present in the binary number: \t %d\n",ocount);
printf("\n------------------------------------------\n");
return 0;
}

OutPut:

C Program to count the number of zeros and ones in a particular position of binary numbers.(Input should be decimal number, convert them to binary number)

/* =====================================================================================
 * *
 * *       Filename:  posbitcount.c
 * *        Created:  Tuesday 3 February 2015
 * *       Compiler:  gcc
 * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 * *   Organization:  SCIS,University of Hyderabad
 * *
 * * =====================================================================================*/

#include<stdio.h>
int decimal_binary(int ar, int n1[]);
int main()
{
int k=0,c1,ni,pos;
int zcount=0,ocount=0;
int arr[100],j;
int n1[100];
printf("\n--------------------------------------------------------\n");
printf("How many integer you wanna insert:");
scanf("%d",&ni);
printf("Enter the elements in to the array:\n");
for(j=0; j<ni; j++)
{
scanf("%d",&arr[j]);
}
printf("\nThe elements of the array are:\n");
for(j=0; j<ni; j++)
{
printf("%d\t",arr[j]);
}
printf("\n--------------------------------------------------------\n");
printf("Enter the position of the bit:");
scanf("%d",&pos);
for(j=0; j<ni; j++)
{
c1=decimal_binary(arr[j],n1);
printf("\nThe binary value of %d is:",arr[j]);
for(k=0; k<c1; k++)
{
printf("%d",n1[k]);
}
if(n1[pos] == 0)
{
zcount++;
}
else
{
ocount++;
}
}
printf("\n--------------------------------------------------------\n");
printf("Position count starts from zero(0)\n");
printf("No of zero in %d position=%d\n",pos,zcount);
printf("No of one in %d position=%d",pos,ocount);
printf("\n--------------------------------------------------------\n");
printf("\n");
return 0;
}
int decimal_binary(int dn, int ar[])
{
int k=0,quo = dn;
int i=1,j;
int binaryNumber[100];
while(quo!=0)
{
binaryNumber[i++]= quo % 2;
quo = quo / 2;
}
for(j = i -1 ;j> 0;j--)
{
ar[k]=binaryNumber[j];
k++;
}
return k;
}

OutPut:

C Program to find the Hamming Distance of all consecutive decimal numbers in an array, find the maximum hamming distance and print the index of these two number.

/* =====================================================================================
 * *
 * *       Filename:  hamdist.c
 * *        Created:  Tuesday 3 February 2015
 * *       Compiler:  gcc
 * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 * *   Organization:  SCIS,University of Hyderabad
 * *
 * * =====================================================================================*/

#include<stdio.h>
int decimal_binary(int ar, int n1[]);
int hamming_distance(int ar[], int ar1[],int p,int q);
int main()
{
int k=0,ni,c1,c2,hd,maxhd=0,minhd=1000;
int no1,no2,maxi1,maxi2,mini1,mini2;
int arr[100],i=1,j;
printf("\n--------------------------------------------------------\n");
printf("How many integer you wanna insert:");
scanf("%d",&ni);
printf("Enter the elements in to the array:\n");
for(j=0; j<ni; j++)
{
scanf("%d",&arr[j]);
}
printf("\nThe elements of the array are:\n");
for(j=0; j<ni; j++)
{
printf("%d\t",arr[j]);
}
printf("\n--------------------------------------------------------\n");
for(j=0; j<ni-1; j++)
{
int n1[100],n2[100];
c1=decimal_binary(arr[j],n1);
c2=decimal_binary(arr[j+1], n2);
printf("The binary value of %d is:",arr[j]);
for(k=0; k<c1; k++)
{
printf("%d",n1[k]);
}
printf("\nThe binary value of %d is:",arr[j+1]);
for(k=0; k<c2; k++)
{
printf("%d",n2[k]);
}
hd=hamming_distance(n1,n2,c1,c2);
printf("\nHamming distance between above two binary number is:%d",hd);
if(hd > maxhd)
{
maxhd=hd;
no1=arr[j];
no2=arr[j+1];
maxi1=j;
maxi2=j+1;
}
else if(hd < minhd)
{
minhd=hd;
no1=arr[j];
no2=arr[j+1];
mini1=j;
mini2=j+1;
}
else{}
printf("\n--------------------------------------------------------\n");
}
printf("The maximum hamming distance is betweeen %d and %d=%d\n",arr[maxi1],arr[maxi2],maxhd);
printf("The index of the two numbers are: %d and %d\n",maxi1,maxi2);
printf("The minimum hamming distance is betweeen %d and %d=%d\n",arr[mini1],arr[mini2],minhd);
printf("The index of the two numbers are: %d and %d\n",mini1,mini2);
printf("\n");
return 0;
}
int decimal_binary(int dn, int ar[])
{
int k=0,quo = dn;
int i=1,j;
int binaryNumber[100];
while(quo!=0)
{
binaryNumber[i++]= quo % 2;
quo = quo / 2;
}
for(j = i -1 ;j> 0;j--)
{
ar[k]=binaryNumber[j];
k++;
}
return k;
}
int hamming_distance(int ar[], int ar1[],int p,int q)
{
int i,j,count=0;
if(p == q)
{
for(i=0; i<p; i++)
{
if(ar[i] != ar1[i])
{
count++;
}
}
return count;
}
else if(p > q)
{
i=p-1;
for(j=q-1; j>=0; j--)
{
if(ar1[j] != ar[i])
{
count++;
}
i--;
}
for(i=p-q-1; i>=0; i--)
{
if(ar[i] == 1)
{
count++;
}
}
return count;
}
else
{
j=q-1;
for(i=p-1; i>=0; i--)
{
if(ar[i] != ar1[j])
{
count++;
}
j--;
}
for(j=q-p-1; j>=0; j--)
{
if(ar1[j] == 1)
{
count++;
}
}
return count;

}
}

OutPut:


C Program to count all possible path from source to destination in a Graph using adjacency matrix.

/* =====================================================================================
 * *
 * *       Filename :  pathcountgraph.c
 * *       Created    :  Tuesday 27 January 2015 17:30:17  IST
 * *       Compiler :  gcc
 * *       Author     :  Manoj Kumar Patra,manojpatra.sit@gmail.com
 * *   Organization:  SCIS,University of Hyderabad
 * *
 * * =====================================================================================*/

#include <stdio.h>

int main()
{
int pl,i,n,c, d, k,source,dest,sum = 0;
int first[10][10], second[10][10], multiply[10][10];
printf("\nEnter the number of nodes:");
scanf("%d", &n);
printf("\n=======================================\n");
printf("Enter the edge(path) of the graph\n");
printf("ENTER '1' if yes, ENTER '0' if no path\n");
printf("\n=======================================\n");

for(c=0;c<n;c++)
{
for(d=0;d<n;d++)
{
first[c][d]=second[c][d]=0;
}
}

for(c=0;c<n;c++)
{
for(d=0;d<n;d++)
{
if(c==d)
continue;
if(first[d][c]==1)
continue;
printf("Is there any path from node '%d' to node '%d':",c+1,d+1);
scanf("%d", &first[c][d]);
second[c][d]=first[c][d];
}
printf("\n");
}

printf("\nThe Adjecency Matrix:\n");
printf("---------------------\n");
for(c=0;c<n;c++)
{
for(d=0;d<n;d++)
{
printf("%d\t",first[c][d]);
}
printf("\n");
}

printf("\n----------------------\n");

printf("\nEnter the length of the path:");
scanf("%d",&pl);

for(i=pl-1;i>0;i--)
{
for(c=0;c<n;c++)
{
for(d=0;d<n;d++)
{
for(k=0;k<n;k++)
{
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
for(c=0; c<n; c++)
{
for(d=0; d<n; d++)
{
second[c][d]=multiply[c][d];
}
}
}
printf("\nThe resultant matrix is:\n");
for (c=0; c<n; c++)
{
for (d=0; d<n; d++)
printf("%d\t", multiply[c][d]);
printf("\n");
}
printf("\nEnter the source:");
scanf("%d",&source);
printf("Enter the destination:");
scanf("%d",&dest);
if(multiply[source-1][dest-1]>0)
{
printf("\nNumber of path from node '%d' to node '%d' is:%d\n",source,dest,multiply[source-1][dest-1]);
}
else
{
printf("\nNo path from nade '%d' to node '%d' ...!!!\n",source,dest);
}

printf("\n");

return 0;
}

C Program to sort the processes according to their priority

/* =====================================================================================
 * *
 * *       Filename:  procPri.c
 * *        Created:  Tuesday 20 January 2015 17:30:17  IST
 * *       Compiler:  gcc
 * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 * *   Organization:  SCIS,University of Hyderabad
 * *
 * * =====================================================================================*/

#include <stdio.h>
#include <stdlib.h>
typedef int (*compfn)(const void*, const void*);
struct process
{
int  priority;
char name[15];
};
struct process array[10]  = { {  1, "Process1"    },
{  5, "Process2" },
{  8, "Process3" },
{  4, "Process4" },
{  3, "Process5" },
{  9, "Process6" },
{  2, "Process7" },
{  6, "Process8" },
{ 10, "Process9" },
{  7, "Process10"}  };

void printarray(void);
int  compare(struct process *, struct process *);
void main(void)
{
printf("List of Processes before sorting:\n");
printarray();

qsort((void *) &array,              // Beginning address of array
10,                         // Number of elements in array
sizeof(struct process),     // Size of each element
(compfn)compare );          // Pointer to compare function

printf("\nList Processes after sorting:\n");
printarray();
}

int compare(struct process *elem1, struct process *elem2)
{
if ( elem1->priority < elem2->priority)
return -1;

else if (elem1->priority > elem2->priority)
return 1;

else
return 0;
}

void printarray(void)
{
int i;
printf("PRI\tPname\n");
printf("----\t-----\n");
for (i = 0; i < 10; i++)
printf("%d\t%s\n",array[i].priority, array[i].name);
}

C Program to perform Set operation.

/* =====================================================================================
 * *
 * *       Filename:  setoperation.c
 * *        Created:  Sunday 11 January 2015 09:10:17  IST
 * *       Compiler:  gcc
 * *         Author:  Manoj Kumar Patra,manojpatra.sit@gmail.com
 * *   Organization:  SCIS,University of Hyderabad
 * *
 * * =====================================================================================*/

#include<stdio.h>
#include<stdlib.h>
void Union(int set1[10],int set2[10],int m,int n);
void Intersection(int set1[10],int set2[10],int m,int n);
void Difference(int set1[10],int set2[10],int m, int n);
void RelativeComplement(int set1[10],int set2[10],int m, int n);
void main()
{
int a[10],b[10],m,n,i,j;
int ch;
printf("\nEnter the number of elements in first set:\n");
scanf("%d",&m);
printf("\nEnter the elements:\n");
for(i=0; i<m; i++)
{
scanf("%d",&a[i]);
}
printf("\nElement of First set:\n\n");
for(i=0;i<m;i++)
{
printf("%d\t",a[i]);
}
printf("\nEnter the number of elements in second set:\n");
scanf("%d",&n);
printf("\nEnter the elements:\n");
for(i=0; i<n; i++)
{
scanf("%d",&b[i]);
}
printf("\nElement of second set\n\n");
for(i=0; i<n; i++)
{
printf("%d\t",b[i]);
}
for(;;)
{
printf("\n\n*****What do you wanna do..??*****\n");
printf("...Menu...\n1.Union\n2.Intersection\n3.Difference\n4.Complement");
printf("\n5.exit");
printf("\nEnter your choice:\n");
scanf("%d",&ch);
switch(ch) {
case 1:
Union(a,b,m,n);
break;
case 2:
Intersection(a,b,m,n);
break;
case 3:
Difference(a,b,m,n);
break;
case 4:
RelativeComplement(a,b,m,n);
break;
case 5:
exit(1);
}
}
}

void Union(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
c[k]=a[i];
k++;
}
for(i=0;i<n;i++)
{
flag=0;
for(j=0;j<m;j++)
{
if(b[i]==c[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=b[i];
k++;
}
}
printf("\nCalculatting...");
printf("\nElement of UNION set:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
void Intersection(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
flag=0;
for(j=0;j<n;j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==1)
{
c[k]=a[i];
k++;
}
}
printf("\nCalculatting...");
if(k==0)
{
printf("\n\nResultant set is null set!\n");
}else{
printf("\nElement of resultant set:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
}
void Difference(int a[10],int b[10],int m,int n)
{
int c[10],i,j,k=0,flag=0;
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=a[i];
k++;
}

}
printf("\nCalculatting...");
if(k==0)
{
printf("\n\nResultant set is null set!\n");
}
else
{
printf("\nElements of Difference set:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
}
void RelativeComplement(int a[10],int b[10],int m,int n)
{
int c[10],d[10],i,j,k=0,l=0,flag=0;
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=a[i];
k++;
}

}
printf("\nCalculatting...");
if(k==0)
{
printf("\n\nThe Relative Complement of set2 in set1 is null set!\n");
}
else
{
printf("\nThe RelativeComplement of set2 in set1:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
printf("\n");
}