Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==========
- Best Fit
- ==========
- #include<stdio.h>
- void main()
- {
- int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999;
- static int barray[20],parray[20];
- printf("\nEnter the number of blocks:");
- scanf("%d",&nb);
- printf("Enter the number of processes:");
- scanf("%d",&np);
- printf("\nEnter the size of the blocks:-\n");
- for(i=1;i<=nb;i++)
- {
- printf("Block no.%d:",i);
- scanf("%d",&b[i]);
- }
- printf("\nEnter the size of the processes :-\n");
- for(i=1;i<=np;i++)
- {
- printf("Process no.%d:",i);
- scanf("%d",&p[i]);
- }
- for(i=1;i<=np;i++)
- {
- for(j=1;j<=nb;j++)
- {
- if(barray[j]!=1)
- {
- temp=b[j]-p[i];
- if(temp>=0)
- if(lowest>temp)
- {
- parray[i]=j;
- lowest=temp;
- }
- }
- }
- fragment[i]=lowest;
- barray[parray[i]]=1;
- lowest=10000;
- }
- printf("\nProcess_no\tProcess_size\tBlock_no\tBlock_size\tFragment");
- for(i=1;i<=np && parray[i]!=0;i++)
- printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,p[i],parray[i],b[parray[i]],fragment[i]);
- }
- ==========================
- First Fit
- ==========================
- ...http://world-of-c-programming.blogspot.com/2012/11/first-fit-memory-management-algorithm.html
- #include<stdio.h>
- #include<conio.h>
- #define max 25
- void main()
- {
- int frag[max],b[max],f[max],i,j,nb,nf,temp;
- static int bf[max],ff[max];
- printf("\n\tMemory Management Scheme - First Fit");
- printf("\nEnter the number of blocks:");
- scanf("%d",&nb);
- printf("Enter the number of files:");
- scanf("%d",&nf);
- printf("\nEnter the size of the blocks:-\n");
- for(i=1; i<=nb; i++)
- {
- printf("Block %d:",i);
- scanf("%d",&b[i]);
- }
- printf("Enter the size of the files :-\n");
- for(i=1; i<=nf; i++)
- {
- printf("File %d:",i);
- scanf("%d",&f[i]);
- }
- for(i=1; i<=nf; i++)
- {
- for(j=1; j<=nb; j++)
- {
- if(bf[j]!=1)
- {
- temp=b[j]-f[i];
- if(temp>=0)
- {
- ff[i]=j;
- break;
- }
- }
- }
- frag[i]=temp;
- bf[ff[i]]=1;
- }
- printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
- for(i=1; i<=nf; i++)
- printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
- getch();
- }
- ==========================
- Worst Fit
- ==========================
- #include<stdio.h>
- #include<conio.h>
- #define max 25
- void main()
- {
- int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
- static int bf[max],ff[max];
- clrscr();
- printf("\n\tMemory Management Scheme - Worst Fit");
- printf("\nEnter the number of blocks:");
- scanf("%d",&nb);
- printf("Enter the number of files:");
- scanf("%d",&nf);
- printf("\nEnter the size of the blocks:-\n");
- for(i=1;i<=nb;i++) {printf("Block %d:",i);scanf("%d",&b[i]);}
- printf("Enter the size of the files :-\n");
- for(i=1;i<=nf;i++) {printf("File %d:",i);scanf("%d",&f[i]);}
- for(i=1;i<=nf;i++)
- {
- for(j=1;j<=nb;j++)
- {
- if(bf[j]!=1) //if bf[j] is not allocated
- {
- temp=b[j]-f[i];
- if(temp>=0)
- if(highest<temp)
- {
- ff[i]=j;
- highest=temp;
- }
- }
- }
- frag[i]=highest;
- bf[ff[i]]=1;
- highest=0;
- }
- printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
- for(i=1;i<=nf;i++)
- printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
- getch();
- }
- ================
- MFT
- ================
- #include<stdio.h>
- #include<conio.h>
- main()
- {
- int mems, bls, nobl, extf,n, mp[10],intf=0;
- int i,p=0;
- printf("Enter the total memory ");
- scanf("%d",&mems);
- printf("Enter the block size ");
- scanf("%d", &bls);
- nobl=mems/bls;
- extf=mems - nobl*bls;
- printf("\nEnter the number of processes ");
- scanf("%d",&n);
- for(i=0; i<n; i++)
- {
- printf("Enter memory required for process %d ",i+1);
- scanf("%d",&mp[i]);
- }
- printf("\nNo. of Blocks available in memory %d",nobl);
- printf("\n\nPROCESS\tMEMORY REQUIRED\t ALLOCATED\tINTERNAL FRAGMENTATION");
- for(i=0; i<n && p<nobl; i++)
- {
- printf("\n %d\t\t%d",i+1,mp[i]);
- if(mp[i] > bls)
- printf("\t\tNO\t\t---");
- else
- {
- printf("\t\tYES\t%d",bls-mp[i]);
- intf = intf + bls-mp[i];
- p++;
- }
- }
- if(i<n)
- printf("\nMemory is Full, Remaining Processes cannot be accomodated");
- printf("\n\nTotal Internal Fragmentation is %d",intf);
- printf("\nTotal External Fragmentation is %d",extf);
- getch();
- }
- ==========================
- Bash (Shell Scripting)
- ==========================
- gub@cseit:~$ ld
- ld: no input files
- gub@cseit:~$ cd Documents
- gub@cseit:~/Documents$ mkdir Tushar
- gub@cseit:~/Documents$ cd Tushar
- gub@cseit:~/Documents/Tushar$ which bash >new.sh
- gub@cseit:~/Documents/Tushar$ ls
- new.sh
- gub@cseit:~/Documents/Tushar$ chmod +x new.sh
- gub@cseit:~/Documents/Tushar$ gedit new.sh
- gub@cseit:~/Documents/Tushar$ gedit new.sh
- gub@cseit:~/Documents/Tushar$ /new.sh
- bash: /new.sh: No such file or directory
- gub@cseit:~/Documents/Tushar$ ./new.sh
- #!/bin/bash
- echo -n "enter a number"
- read n
- for ((i=1;i<=n; i++))
- do
- echo "Output $i"
- done
- ---------------------------------
- #!/bin/bash
- echo -n "enter a number"
- read n
- sum=0
- for ((i=1;i<=n; i++))
- do
- sum=$((sum+i))
- done
- echo "Output is $sum"
- ----------------------------
- Taking input in array :
- >>>>>>>>>>>>>>>>>>>>>>
- #!/bin/bash
- echo -n "enter limit: "
- read n
- echo "Enter Numbers: "
- for ((i=0;i<n; i++))
- do
- read a[$i]
- done
- ##!/bin/bash
- echo -n "enter limit: "
- read n
- echo "Enter Numbers: "
- #!/bin/bash
- echo "Enter the first number :"
- read a
- echo "Enter the second number : "
- read b
- if [ $a -gt $b ]
- then
- num=$a
- den=$b
- else
- num=$b
- den=$a
- fi
- r=`expr $num % $den`
- while [ $r -ne 0 ]
- do
- num=$den
- den=$r
- r=`expr $num % $den`
- done
- gcd=$den
- lcm=`expr $a \* $b / $gcd`
- echo " The LCM of $a and $b is : $lcm"
- echo " The GCD of $a and $b is : $gcd"
- leaf year...
- echo "Enter Year:"
- read y
- year=$y
- y=$(( $y % 4 ))
- if [ $y -eq 0 ]
- then
- echo "$year is Leap Year!"
- else
- echo "$year is not a Leap Year!"
- fi
- prime number...
- echo "Enter a number: "
- read num
- i=2
- f=0
- while [ $i -le `expr $num / 2` ]
- do
- if [ `expr $num % $i` -eq 0 ]
- then
- f=1
- fi
- i=`expr $i + 1`
- done
- if [ $f -eq 1 ]
- then
- echo "The number is composite"
- else
- echo "The number is Prime"
- fi
- Armstrong number or not...
- echo "Enter a number: "
- read c
- x=$c
- sum=0
- r=0
- n=0
- while [ $x -gt 0 ]
- do
- r=`expr $x % 10`
- n=`expr $r \* $r \* $r`
- sum=`expr $sum + $n`
- x=`expr $x / 10`
- done
- if [ $sum -eq $c ]
- then
- echo "It is an Armstrong Number."
- else
- echo "It is not an Armstrong Number."
- fi
- factorial number....
- echo "Enter a number"
- read num
- fact=1
- while [ $num -gt 1 ]
- do
- fact=$((fact * num)) #fact = fact * num
- num=$((num - 1)) #num = num - 1
- done
- echo $fact
- palindrome.....
- echo "enter the string "
- read name
- name1=$(echo $name | rev)
- if [ $name = $name1 ]
- then
- echo "$name is palindrome"
- else
- echo "$name is not a palindrome"
- fi
- sum of natural ...
- echo "Sum of n natural numbers \n”
- echo "Enter the value of n "
- read n
- i = 0
- sum = 0
- while[$i –lt $n]
- do
- sum=’expr $sum + expr $i’
- i = ‘expr $i + 1’
- done
- echo "Sum of n natural numbers are : $sum”
- #shell script to check whether a number is positive or negative
- echo "Enter a Number"
- read num
- if [ $num -lt 0 ]
- then
- echo "Negative"
- elif [ $num -gt 0 ]
- then
- echo "Positive"
- else
- echo "Neither Positive Nor Negative"
- fi
- odd or even....
- echo -n "Enter numnber : "
- read n
- rem=$(( $n % 2 ))
- if [ $rem -eq 0 ]
- then
- echo "$n is even number"
- else
- echo "$n is odd number"
- fi
- addition using loop....
- n=$1
- result=0
- j=0
- ADD(){
- result=`expr $result + $j`
- }
- #for (( i=1; i<=$n; i++ ))
- for i in {0..$n..1}
- do
- ADD
- j=`expr $j + $1`
- done
- echo $result
- …….
- #!/bin/bash
- num1=1
- num2=10
- if [ $num1 -gt $num2 ]; then
- echo "number one is greather "
- else
- echo "number two is greater"
- fi
- @for comapre number
- ...................................
- #!/bin/bash
- num1=1
- num2=10
- if [ $num1 -eq $num2 ]; then
- echo "number is equel "
- else
- echo "not equel"
- fi
- @for check odd or even number
- ......................
- #!/bin/bash
- echo -n "please enter a number"
- read n
- check=$(($n % 2))
- if [ $check -eq 0 ];then
- echo "$n is an even number"
- else
- echo "$n is an odd number"
- fi;
- -------------------------------
- @for string comparisom
- #!/bin/bash
- num1="jahid"
- num2="arif"
- if [ $num1 = $num2 ]; then
- echo "name is equal "
- else
- echo "not equal"
- fi
- -----------------------
- @FOR counting
- #!/bin/bash
- COUNT=6
- while [ $COUNT -gt 0 ]; do
- echo value of count is: $COUNT
- let COUNT=COUNT-1
- done
- ----------------
- @ for reverse
- #!/bin/bash
- COUNT=1
- while [ $COUNT -lt 7 ]; do
- echo value of count is: $COUNT
- let COUNT=COUNT+1
- done
- -----------------------
- #!/bin/bash
- COUNT=0
- until [ $COUNT -gt 5 ]; do
- echo value of count is: $COUNT
- let COUNT=COUNT+1
- done
- @ addition
- echo '#### let ###'
- let addition=3+5
- echo "3+5 =" $addition
- @subtraction
- echo '#### let ###'
- let subtraction=5-3
- echo $subtraction
- @power of
- echo '#### let ###'
- let poweroftwo=2**2
- echo "2^ 2=" $poweroftwo
- @mathmatatics
- echo 2^8 =$[ 2** 8 ]
- =====================
- Linux Commands
- =====================
- cd > changing directory
- ls > seeing list
- clear > clearing terminal screen
- cd - > backing a from directory
- cd .. > backing from a directory
- cd ~ > jump to the home directory
- mkdir > making or creating new folder
- rmdir > removing or deleting a directory
- mv > renaming a folder or file
- touch > creating a new file
- rm > removing a file
- pwd > Shows the working directory name with path
- (cat >file1.txt ) > Creating new file with contents
- ctrl+z > (to exit from editor of consents)
- gedit fileName.extension > for opening a specific file
- ls b* > show the file list that starts with b and then one or more character
- ls *l* > shows characters that has before and after some character before and after 'l'
- ls ?l* > Shows the list that has 1 character before 'l' and one or more character after 'l'
- ls [rt]* > Shows the list that starts with 'r' and 't'
- ls *[0-9]* > Shows the list that contains numeric number (0-9)
- ls [^a-k]* > Shows the list that does not starts with "a" to "k".
- head -4 ba.txt > shows the first 4 list from the file named ba.txt
- tail -3 ba.txt > shows the last 3 list from the file named ba.txt
- sort ba.txt > sort the contents alphabetically
- nl ba.txt > Shows the line number of the contents of the file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement