Showing posts with label File Allocation Techniques. Show all posts
Showing posts with label File Allocation Techniques. Show all posts

Thursday, 1 November 2018

SEQUENTIAL FILE ALLOCATION

#include <stdio.h>
int main(){
int a1[50],n,i,j,k,nb,st;
for(i=0;i<50;i++)
a1[i]=0;
do{
k=0;
printf("Enter number of blocks and number of starting block\n");
scanf("%d%d",&nb,&st);
for(i=st;i<(st+nb);i++){
if(a1[i]==0)
k+=1;
}
if(k==nb){
for(i=st;i<(st+nb);i++){
     a1[i]=1;
     j+=1;
}
printf("File allocated successfully\n");
}
else{
printf("File cannot be allocated\n");
}
printf("Do you want to continue to insert another file\n1.YES\t2.NO\n");
scanf("%d",&i);
}while(i==1);
return 0;
}



LINKED FILE ALLOCATION

#include <stdio.h>
int main(){
int a1[50],i=0,j=0,k=0,nb=0,st=0,l=0,te=0;
for(i=0;i<50;i++)
a1[i]=0;
printf("Enter how many blocks already allocated\n");
scanf("%d",&l);
printf("Enter the block numbers\n");
for(i=0;i<l;i++){
scanf("%d",&j);
a1[j]=1;
}
do{
k=0;
printf("Enter start block number and length of file in blocks: \n");
scanf("%d%d",&st,&nb);
k=nb;
for(i=st;i<(st+k);i++){
if(a1[i]==0){
a1[i]=1;
printf("%d-->%d\n",i,1);
te++;}
else{
k++;
printf("%d is ALready occupied block\n",i);
}
}
if(te==0&&k==nb){
printf("File cannot be allocated\n");
}
printf("Do you want to continue to insert another file\n1.YES\t 2.NO\n");
scanf("%d",&i);
}while(i==1);
return 0;
}



Operating Systems:Indexed File Allocation

#include <stdio.h>

int main(){
int a1[50],a2[50],k=0,i,j,n,m;
for(i=0;i<50;i++)
{a1[i]=0;a2[i]=0;
}
do{
k=0;
printf("Enter indexed block number\n");
scanf("%d",&m);
if(a1[m]==0){
a1[m]=1;
do{
k=0;
printf("Enter number of blocks for file\n");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("ENter block number\n");
scanf("%d",&a2[i]);
if(a1[a2[i]]==0)
k++;
}
if(k==n){
             for(i=0;i<n;i++){
              a1[a2[i]]=1;
             }
             printf("File allocated\n");
}
else{
     printf("Try another block set\n");
}
}while(k!=n);
}
else{
printf("Index is already assigned\n");
}
printf("Enter 1 if you want to insert other files else 0\n");
scanf("%d",&i);
}while(i==1);
}




FERMATS LITTLE THEOREM

import java.math.*; import java.io.*; import java.util.Scanner; public class Main { public static void main(String[] args) {    Sca...