Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- void recursion(int file[])
- {
- int free = 0, block, length, j, k, ch, i;
- printf("Enter the starting block and the length: ");
- scanf("%d%d", &block, &length);
- for (i = block; i < block + length; i++)
- {
- if (file[i] == 0)
- {
- free++;
- }
- }
- if (length == free)
- {
- for (i = block; i < block + length; i++)
- {
- if (file[i] == 0)
- {
- file[i] = 1;
- printf("%d\t%d\n", i, file[i]);
- }
- }
- if (i != (block + length - 1))
- {
- printf("The file is allocated to the disk\n");
- }
- }
- else
- {
- printf("Another File Exists in the Required Block \n");
- }
- printf("Do you want to enter files\n");
- printf("Press 1 for YES, 0 for NO: ");
- scanf("%d", &ch);
- if (ch == 1)
- recursion(file);
- else
- exit(0);
- return;
- }
- int main()
- {
- int file[30], i;
- for (i = 0; i < 30; i++)
- {
- file[i] = 0;
- }
- printf("Files allocated are\n");
- recursion(file);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment