The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
[CPU scheduling process] sorting processes
Discuss [CPU scheduling process] sorting processes in the C Programming forum on Dev Shed. [CPU scheduling process] sorting processes C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 21st, 2013, 02:07 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 13
Time spent in forums: 7 h 8 m 34 sec
Reputation Power: 0
|
|
|
[CPU scheduling process] sorting processes
Hi everyone, i could not find a way to solve my problem so i registered here in hope that somebody can help me. My problem is about the FCFS,in ordering the processes basing to their arrival time. Im new to arrays.
in example:
PROCESS NAME---BURST TIME----ARRIVAL TIME
p0------------------3-----------------9
p1------------------5-----------------4
p2------------------3-----------------7
p3------------------2-----------------0
p4------------------5-----------------2
so if im to sort them in ascending order it should look like this
PROCESS NAME---BURST TIME----ARRIVAL TIME
p3------------------2-----------------0
p4------------------5-----------------2
p1------------------5-----------------4
p2------------------3-----------------7
p0------------------3-----------------9
and here is my code so far
#include <stdio.h>
#include<conio.h>
main()
{
int bt[10],at[10],tc[10],a,b,c,temp,np,totalwt=0;
float tat,wt,avgtat,avgwt;
char name[10][10];
for(a=0;a<10;a++)
{
bt[a]=0;
at[a]=0;
}
//input no.of processes
printf("NO. OF PROCESS: ");
scanf("%d", &np);
system("cls");
//input burst times
printf("\nBURST TIMES: ");
for(a=0;a<np;a++)
scanf("%d", &bt[a]);
system("cls");
//inputarrival times
printf("\nARRIVAL TIMES: ");
for(a=0;a<np;a++)
scanf("%d",&at[a]);
system("cls");
//computation
for(a=0;a<10;a++)
{
for(b=b+1;b<10;b++)
{
if(at[a]>at[b])
{
at[a]=temp;
at[a]=at[b];
at[b]=temp;
}
}
}
printf("\n\nPROCESS BURST TIME ARRIVALTIME\n");
for(a=0;a<np;a++)
printf("\np%d\t\t%d\t\t%d", a, bt[a],at[a]);
for(b=0;b<10;b++)
getch();
}
it willbe very much appreciated to whoever who can help me
|

January 25th, 2013, 05:07 PM
|
 |
Contributing User
|
|
|
|
Let's remove variables unused in the post. Repair the pattern for "swap". Sort all arrays in the same way so they stay aligned. See other /* comments */ . Fixing the process name ordering remains an exercise.
Code:
#include<stdio.h>
int main() { /* int main() */
int bt[10],at[10],a,b,temp,np;
for(a=0;a<10;a++) {
bt[a]=0;
at[a]=0;
}
fputs("NO. OF PROCESS: ",stdout);
scanf("%d", &np);
if ((np < 0) || (10 < np)) /* insert error checks */
return fputs("\nsorry, 0 to 10 are valid\n",stderr),1;
//input burst times
fputs("\nBURST TIMES: ",stdout);
for(a=0;a<np;a++)
scanf("%d",bt+a);
//inputarrival times
fputs("\nARRIVAL TIMES: ",stdout);
for(a=0;a<np;a++)
scanf("%d",at+a);
for(a=0;a+1<np;a++) /* fix the indexing */
for(b=a+1;b<np;b++) /* fix the indexing more */
if(at[a]>at[b]) {
temp = at[a]; at[a]=at[b]; at[b]=temp; /* swap both arrays (and name as well) */
temp = bt[a]; bt[a]=bt[b]; bt[b]=temp;
}
puts("\n\nPROCESS\tBURST TIME\tARRIVAL TIME"); /* improve formatting */
for(a=0;a<np;a++)
printf("\np%d\t\t%d\t\t%d", a, bt[a],at[a]);
putchar('\n');
getchar();
return 0; /* main returns a value to operating system */
}
__________________
[code] Code tags[/code] are essential for python code!
Last edited by b49P23TIvg : January 25th, 2013 at 05:09 PM.
|

January 30th, 2013, 02:26 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 13
Time spent in forums: 7 h 8 m 34 sec
Reputation Power: 0
|
|
|
thank you! this has been a great help =)
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|