Can you write the algorithm for this code?
#include<stdio.h>
int main() {
int process[20], priority[20], arrival_time[20],
burst_time[20], turnaround_time[20], waiting_time[20];
int i, j, limit, sum = 0, position, temp;
float average_wait_time, average_turnaround_time;
printf("Enter Total Number of Processes:\t");
scanf("%d", &limit);
printf("\nEnter Burst Time and Priority For %d
Processes\n", limit);
for(i = 0; i < limit; i++) {
printf("\nProcess[%d]\n", i + 1);
printf("Process Burst Time:\t");
scanf("%d", &burst_time[i]);
printf("Process Priority:\t");
scanf("%d", &priority[i]);
process[i] = i + 1;
}
for(i = 0; i < limit; i++) {
position = i;
for(j = i + 1; j < limit; j++) {
if(priority[j] < priority[position])
{
position = j;
}
}
temp = priority[i];
priority[i] = priority[position];
priority[position] = temp;
temp = burst_time[i];
burst_time[i] = burst_time[position];
burst_time[position] = temp;
temp = process[i];
process[i] = process[position];
process[position] = temp;
}
waiting_time[0] = 0;
for(i = 1; i < limit; i++) {
waiting_time[i] = 0;
for(j = 0; j < i; j++)
{
waiting_time[i] = waiting_time[i] + burst_time[j];
}
sum = sum + waiting_time[i];
}
average_wait_time = sum / limit;
sum = 0;
printf("\nProcess ID\t\tBurst Time\t Waiting Time\t
Turnaround Time\n");
for(i = 0; i < limit; i++) {
turnaround_time[i] = burst_time[i] + waiting_time[i];
sum = sum + turnaround_time[i];
printf("\nProcess[%d]\t\t%d\t\t %d\t\t %d\n", process[i],
burst_time[i], waiting_time[i], turnaround_time[i]);
}
average_turnaround_time = sum / limit;
printf("\nAverage Waiting Time:\t%f", average_wait_time);
printf("\nAverage Turnaround Time:\t%f\n",
average_turnaround_time);
return 0;
}
The algorithm for the given code is:
Step 1: Start
Step 2: Declare variables process[20], priority[20],
arrival_time[20], burst_time[20], turnaround_time[20],
waiting_time[20], i, j, limit, sum = 0, position, temp,
average_wait_time, average_turnaround_time.
Step 3: Display Enter Total Number of Processes
Step 4: Read the variable limit.
Step 5: Display Enter Burst Time and Priority For
Processes
Step 6: for i = 0 To limit-1
Step 6.1: Display Process i + 1
Step 6.2: Display Process Burst Time
Step 6.3: Read variable burst_time[i]
Step 6.4: Display Process Priority
Step 6.5: Read variable priority[i]
Step 6.6: process[i] = i + 1
Step 7.: for i = 0 To limit-1
Step 7.1: position = i
Step 7.2: for j = i + 1 To limit-1
Step 7.2.1: if priority[j] <
priority[position]
Step 7.2.1.0:
position = j;
Step 7.3: temp = priority[i]
Step 7.4: priority[i] = priority[position]
Step 7.5: priority[position] = temp
Step 7.6: temp = burst_time[i]
Step 7.7: burst_time[i] = burst_time[position]
Step 7.8: burst_time[position] = temp
Step 7.9: temp = process[i]
Step 7.10: process[i] = process[position]
Step 7.11: process[position] = temp
Step 8: waiting_time[0] = 0
Step 9: for i = 1 To limit-1
Step 9.1: waiting_time[i] = 0
Step 9.2: for j = 0 To i-1
Step 9.2.1: waiting_time[i] =
waiting_time[i] + burst_time[j]
Step 9.3: sum = sum + waiting_time[i]
Step 10: average_wait_time = sum / limit
Step 11: sum = 0
Step 12: Display Process ID Burst Time Waiting Time Turnaround
Time
Step 13: for i = 0 To limit -1
Step 13.1: turnaround_time[i] = burst_time[i] +
waiting_time[i]
Step 13.2: sum = sum + turnaround_time[i]
Step 13.3: Display process[i], burst_time[i],
waiting_time[i], turnaround_time[i]
Step 14: average_turnaround_time = sum / limit
Step 15: Display average_wait_time
Step 16: Display average_turnaround_time
Step 17: Stop
Can you write the algorithm for this code? #include<stdio.h> int main() { int process[20], priority[20], arrival_time[20],...
C program-- the output is not right please help me to correct it. #include <stdio.h> int main() { int arr[100]; int i,j,n,p,value,temp; printf("Enter the number of elements in the array: \n "); scanf("%d",&n); printf("Enter %d elements in the array: \n",n); for(i=0;i<n;i++) { printf("\nelement %d: ",i); scanf("\n%d",&arr[i]); } printf("\nEnter the value to be inserted: \n "); scanf("\n%d",&value); printf("The exist array is: \n"); for(i=0;i<n;i++) { printf("%d",arr[i]); } p=i; for(i=0;i<n;i++) if(value<arr[i] ) { p = i; break; } arr[p]=value; printf("\n"); for (i =...
i need flowchart for the following c code #include <stdio.h> int main() { int n, i, sum = 0; printf("Enter an integer: "); scanf("%d",&n); i = 1; while ( i <=n ) { sum += i; ++i; } printf("Sum = %d",sum); return 0; }
Do you have a flowgorithim flow chart for this code? #include <stdio.h> int main() { int num,i=0,sum=0; float average; int customerNumbers[num]; int customerSales[num]; printf("How many customers do you want to track?\n"); scanf("%d",&num); while(i<num) { printf("Enter the customer number. "); scanf("%d",&customerNumbers[i]); printf("Enter the sales for the customer "); scanf("%d",&customerSales[i]); i++; } printf("Sales for the Customer"); printf("\nCustomer Customer"); printf("\nNumber Sales"); for(i=0;i<num;i++) { printf("\n %d \t %d",customerNumbers[i], customerSales[i]); sum=sum+customerSales[i]; } average=(int)sum/num; printf("\n Total sales are $%d",sum); printf("\n Average sales are $%.2f",average); printf("\n --------------------------------------------");...
#include<stdio.h> int main() { int data[10], i, j, temp; printf("Enter 10 random number to sort in ascending order:\n"); for(i = 0; i < 10; i++) scanf("%d", &data[i]); /* Sorting process start */ ****** INSERT YOUR CODE TO COMPLETE THE PROGRAM ****** printf("After sort\n"); for(i = 0; i < 10; i++) printf("%d\n",data[i]); return 0; } Looking for alternative solutions for the program code.
Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...
i need help converting this code to java please #include<stdio.h> typedef struct{ int pid,at,bt,ct,tat,wt,f; }process; int main() { int n,i,j,st=0,c,tot=0,pno=0,swi=0; float atat=0,awt=0; printf("enter no of processes : "); scanf("%d",&n); process a[n],temp; for (i=0;i<n;i++){ a[i].pid=i+1; a[i].f=0; printf("enter at : "); scanf("%d",&a[i].at); printf("enter the bt : "); scanf("%d",&a[i].bt); printf("--------------------------- "); } while(1){ int min=999,c=n; if (tot==n) break; for (i=0;i<n;i++){ if ((a[i].at<=st)&&(a[i].f==0)&&(a[i].at<min)){ min=a[i].at; c=i; } } if(pno!=a[c].pid) swi++; if (c==n) st++; else{ a[c].ct=st+a[c].bt; st=st+a[c].bt; a[c].tat=a[c].ct-a[c].at; atat=atat+a[c].tat; a[c].wt=a[c].tat-a[c].bt; awt=awt+a[c].wt; a[c].f=1; tot++; } } printf("...
#include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...
Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...
Explain the code and analyze the performance of algorithm #include<stdio.h> #include<string.h> #define NUM 100 #define maxint 10000 void dijkstra(int n,int v,int dist[],int prev[],int c[][NUM]) { int i,j; bool s[NUM]; for(i=1; i<=n; i++) { dist[i] = c[v][i]; s[i] = false; if (dist[i]>maxint) prev[i] = 0; else prev[i] = v; } dist[v] = 0; s[v] = true; for(i=1; i<n; i++) { int tmp = maxint; int u = v; for(j=1; j<=n; j++) if(!(s[j]) && (dist[j]<tmp)) { u = j; tmp = dist[j]; ...
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } } return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...