Professional Documents
Culture Documents
3) voter
echo Enter your age :-
read age
if [ $age -lt 18 ]
then
echo NOT Eligible
else
echo Eligible
fi
8) Different operations
echo Enter 1 to print each number 1 from number 2
echo Enter 2 to print the reverse of a number
echo Enter 3 to print sum of digits of a number
echo Enter 4 to print factorial of a number
echo Enter 5 to print the fibonacci series of n terms
echo Enter your choice
read ch
case $ch in
1)echo Enter two Numbers
read a b
while [ $a -le $b ]
do
echo $a
a=`expr $a + 1`
done
;;
9) patterns
i=0
j=0
m=`expr $n \* 2`
while [ $i -le $n ]
do
j=0
while [ $j -le $m ]
do
if [ `expr $i + $j` -ge $n -a `expr $j - $i` -le $n ]
then
echo -n " * "
else
echo -n " "
fi
j=`expr $j + 1`
done
echo
i=`expr $i + 1`
done
;;
*)
echo WRONG CHOICE!!
esac
10) FCFS
#include<stdio.h>
int main() {
int
n,i=0,burstTime[10],arrivalTime[10],turnAroundTime[10],waitingTime[10],finishTime[10];
int sum=0,sum_TAT=0,sum_WT=0;
11) SJF
#include<stdio.h>
int main() {
int n,i=0,j=0,temp1=0,temp2=0,sum=0,sum_TAT=0,sum_WT=0;
int
burstTime[10],arrivalTime[10],waitingTime[10],turnAroundTime[10],finishTime[10],process[10];
printf("Enter the Number of Process : \n");
scanf("%d",&n);
printf("Enter the Burst Time : \n");
for(i=0;i<n;i++) {
scanf("%d",&burstTime[i]);
process[i]=i+1;
}
printf("Enter the Arrival Time : \n");
for(i=0;i<n;i++){
scanf("%d",&arrivalTime[i]);
}
for(i=0;i<n-1;i++){
for(j=0;j<n-i-1;j++) {
if(burstTime[j] > burstTime[j+1]) {
temp1 = burstTime[j];
burstTime[j] = burstTime[j+1];
burstTime[j+1] = temp1;
temp2 = process[j];
process[j] = process[j+1];
process[j+1] = temp2;
}
}
}
for(i=0;i<n;i++) {
sum += burstTime[i];
finishTime[i] = sum;
turnAroundTime[i] = finishTime[i] - arrivalTime[i];
sum_TAT += turnAroundTime[i];
waitingTime[i] = turnAroundTime[i] - burstTime[i];
sum_WT += waitingTime[i];
}
printf("\n----------------------------------------------\n");
for(i=0;i<n;i++)
printf("P%d\t",process[i]);
printf("\n-----------------------------------------------\n");
for(i=0;i<n;i++)
printf("%d\t",finishTime[i]);
printf("\n\nAverage Turn Around Time = %.3f",(float)sum_TAT/n);
printf("\nAverage Waiting Time = %.3f\n",(float)sum_WT/n);
return 0;
}
while [ $m -gt 0 ]
do
x=`expr $m % 10`
sum=`expr $sum + $x`
m=`expr $m / 10`
done
p=$sum
while [ $p -gt 0 ]
do x=`expr $p % 10`
rev=`expr $rev \* 10 + $x`
p=`expr $p / 10`
done
for(int i=0;i<p_num;i++) {
for(int j=0;j<r_num;j++) {
Need[i][j]=Max[i][j]-Allocation[i][j];
}
}
bool finish[p_num]={false},check=false;
int answer[p_num]={0},index=0;
for(int x=0;x<p_num;x++) {
for(int i=0;i<p_num;i++) {
for(int j=0;j<r_num;j++) {
bool flag=true;
for(int i=0;i<p_num;i++) {
if(finish[i]==false)
flag=false;
}
if(flag) {
cout<<"The Safe State is : ";
for(int i=0;i<p_num;i++) {
cout<<"P"<<answer[i]+1<<" ";
}
cout<<"\n";
}
else {
cout<<"The system is not in Safe State.\n";
}
return 0;
}