Shell programming, reverse of a number


# Shell Programming
# Reverse a number

echo -n "Enter a number : "
        read n

ori=$n
i=0

while [ $n -gt 10 ]
do
mod=`expr $n % 10`
i=`expr $i \* 10 + $mod`
n=`expr $n / 10`
done

i=`expr $i \* 10 + $n`
echo "Entered Number : $ori"
echo "Reversed Number : $i"

Shell programming - array sorting


# Shell programming
# Sorting 5 numbers

echo "Enter 5 values : "
for i in 0 1 2 3 4
do
read a[$i]
done

echo "Entered Values are "
for (( i=0; i<5; i++))
do
echo -e "\t ${a[$i]}"
done



// Sorting loop
for ((i=0;i<4;i++))
do
for ((j=`expr $i + 1`; j<5;j++))
do
if [ ${a[$j]} -lt ${a[i]} ]
then
t=${a[$i]}
          a[$i]=${a[$j]}
          a[$j]=$t
fi
done
done

// Output
echo "Sorted Numbers : "
for ((i=0;i<5;i++))
do
echo -e "\t ${a[$i]}"
done

Shell programming array biggest and smallest element


# Shell programming
# Read and display array.
# Find biggest and smallest in array

echo "Enter 5 values : "
for i in 0 1 2 3 4
do
read a[$i]
done

echo "Entered values are "
for (( i=0; i<5; i++))
do
echo -e "\t ${a[$i]}"
done

big=${a[0]}
small=${a[0]}

for ((i=1;i<5;i++))
do
if [ $big -lt ${a[i]} ]
then
     big=${a[$i]}
fi

if [ $small -gt ${a[$i]} ]
then
     small=${a[$i]}
fi
done

echo "Biggest is $big"
echo "Smallest is $small"

Shell programming - Number of digits in a number

# Shell programming
# Number of digits in a number

echo -n "Enter a number : "
read n

i=1
while [ $n -gt 10 ]
do
n=`expr $n / 10`
i=`expr $i + 1`
done

echo “Number of digits is $i”

Shell programming - Squares and cubes up to given number

# Shell programming
# Squares and Cubes up to given number

echo -n "Enter a number : "
read n
echo -e "\t Number \t Square \t Cube"
i=1
while [ $i -le $n ]
do
sq=`expr $i \* $i`
cu=`expr $i \* $sq`

echo -e "\t $i \t\t $sq \t\t $cu "
i=`expr $i + 1`
done

Shell programming - Number - positive negative or zero

# Shell Programming 
# Positive negative or zero

echo -n "Hello "; logname
echo -n "enter a number : "
read a
if [ $a -lt 0 ]
then
echo " $a is negetive"
elif [ $a -gt 0 ]
then
echo "$a is Positive"
else
echo "$a is Zero"
fi

3. d. Scheduling algorithm - Round Robin

3. d. Scheduling algorithm - Round Robin



















3. c. Scheduling algorithm - Priority Scheduling

3. c. Scheduling algorithm - Priority Scheduling



















3. b. Scheduling algorithm - SJF

3. b. Scheduling algorithm - SJF



















Simulation of Unix Commands - wc


SIMULATION OF UNIX COMMANDS - Word Count (wc)

Programs
// 4. wc command
#include<stdio.h>
int wc,lc,cc;

main(int argc, char * argv[] )
{
FILE *fp;
int i;
char a[100];

if(argc!=2)
{
          printf(“Usage error”);
          return;
}

fp = fopen(argv[1],"r");
if(fp==NULL)
{
          printf("File opening error");
          return;
}

i=load(fp,a);
while(i==1)
{
          count(a);
          i=load(fp,a);
}

printf("\nWord Count : %d", wc);
printf("\nLine Count : %d", lc);
printf("\nCharacter Count : %d", cc);

close(fp);
}



load(fp1,g)
FILE *fp1;
char g[];
{
          int n;
         
          for(n=0;(g[n]=getc(fp1))!=EOF;n++)
                   if(g[n]=='\n')
                   {
                             g[n]='\0';
                             return 1;
                   }
          return 0;
}

count(g)
char g[];
{
          int n;
          for(n=0;g[n]!='\0';n++)
          {
                   lc++;
                   if(g[n]!='\t' && g[n]!=' ' )
                             cc++;
                   if( (g[n]=='\t' && g[n+1]!='\t' )||(g[n]==' ' && g[n+1]!=' ' ) )
                             wc++;
          }
}





10. c. Page Replacement Algorithms - LRU


10. c. Page Replacement Algorithms - LRU








10. b. Page Replacement Algorithms - Optimal


10. b. Page Replacement Algorithms - Optimal








11. d. File Organization - DAG Directory Structure


11. d.  File Organization - DAG Directory Structure











11. c. File Organization - Hierarchical Directory Structure



11. c.  File Organization - Hierarchical Directory Structure