C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 21st, 2013, 02:07 PM
Kuiva Kuiva is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 13 Kuiva User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old January 25th, 2013, 05:07 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
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.

Reply With Quote
  #3  
Old January 30th, 2013, 02:26 PM
Kuiva Kuiva is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 13 Kuiva User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 8 m 34 sec
Reputation Power: 0
thank you! this has been a great help =)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > [CPU scheduling process] sorting processes

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap