the SJN and the FCFS will not continue to answer the problem...
when i choose one of the task listed (SJN and FCFS others are not filled) it proceed to inputting value,
after inputting the data it exitS or stop.. help me to display the answer..

`````` #include<conio.h>
#include<stdio.h>
#include<math.h>

int choose();
void sjn();
void fcfs();

void main()
{
int input;

clrscr();
printf("\n\n**************CPU Scheduling*************\n");
printf("|\tChoose CPU Scheduling:\t\t|\n|\t1. Shortest Job Next\t\t|\n|\t2. First Come First Serve\t|\n|\t3. Round Robin\t\t\t|\n|\t4. All CPU Scheduling.\t\t|\n*****************************************\n");
scanf("%d",&input);

switch(input)
{
case 1:sjn();
break;
case 2:fcfs();
default:
printf("Invalid input");
}

}
//******************SJN*******************
void sjn()
{
int s,t[20],temp,n,x[20],w[20],i,j,c,d,b[20];
float average;

printf("SJN\n");
printf("Enter The Job  3-5:");

scanf("%d",&n);
if(n<=5){
if(n==3){
printf("Enter the Time of Job A,B,C:\n");
}
if(n==4){
printf("Enter the Time of Job A,B,C,D:\n");
}
if(n==5){
printf("Enter the Time of Job A,B,C,D,E:\n");
}
for(i=1;i<=n;i++)
{
scanf("%d",&b[i]);
x[i]=i;
}
for(i=1;i<=n-1;i++)
{
for(j=i+1;j<=n;j++)
{
if(b[i]>b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
s=x[i];
x[i]=x[j];
x[j]=s;
}
}
}
c=0;
d=0;
for(i=1;i<=n;i++)
{
w[i]=w[i-1]+b[i-1];
t[i]=b[i]+t[i-1];
w[1]=0;
t[1]=b[1];
c+=w[i];
d+=t[i];
}
average=(float)d/n;
printf("Job List\n");
for(i=1;i<=n;i++)
{
if(x[i]==1)
printf("A");
if(x[i]==2)
printf("B");
if(x[i]==3)
printf("C");
if(x[i]==4)
printf("D");
if(x[i]==5)
printf("E");
else
printf("");
printf("\n");
}
for(i=1;i<=n;i++)
{
if(i==n){
printf("Time Consumed: %d\n",t[i]);
printf("Average Turn-Around Time: %.2f",average);
}
}
}
else{
printf("Invalid Input");
}
}
//*******************FCFS*******************
void fcfs()
{
char char2,char3,char4,char5,char6,char7,char8,char9;
int input,num1,num2,num3,num4,num5;
int out1,out2,out3,out4,out5,out6;

printf("***********FIRT COME FIRST SERVE****************\n");
printf("Enter How Many Jobs 4-5: ");
scanf("%d",&input);
if(input==4){
printf("Enter The 1st Job:\n");
scanf("%s",&char7);
printf("Enter The 2nd Job:\n");
scanf("%s",&char6);
printf("Enter The 3rd Job:\n");
scanf("%s",&char2);
printf("Enter The 4th Job:\n");
scanf("%s",&char4);
printf("Enter The Time Job %c, Job %c, Job %c And Job %c :\n",char7,char6,char2,char4);
scanf("%d%d%d%d",&num1,&num2,&num3,&num4);
out1=num1+num2;
out2=num3+out1;
out3=num4+out2;
out4=num1+out1+out2+out3;
out5=out4/4;
printf("All Job Executed: %c %c %c %c \n",char7,char6,char2,char4);
printf("Time Consumed: %d \n",out3);
printf("Average Turn-Around Time: %d",out5);
}
if(input==5){
printf("Enter The 1st Job:\n");
scanf("%s",&char9);
printf("Enter The 2nd Job:\n");
scanf("%s",&char6);
printf("Enter The 3rd Job:\n");
scanf("%s",&char8);
printf("Enter The 4th Job:\n");
scanf("%s",&char4);
printf("Enter The 5th Job:\n");
scanf("%s",&char3);
printf("Enter The Time Job %c, Job %c, Job %c, Job %c And Job %c :\n",char9,char6,char8,char4,char3);
scanf("%d%d%d%d%d",&num1,&num2,&num3,&num4,&num5);
out1=num1+num2;
out2=num3+out1;
out3=num4+out2;
out4=num5+out3;
out5=num1+out1+out2+out3+out4;
out6=out5/5;
printf("All Job Executed: %c %c %c %c %c\n",char9,char6,char8,char4,char3);
printf("Time Consumed: %d ",out4);
printf("Average Turn-Around Time: %d",out6);
}
}
//*****************ROUNDBROBIN***************
void rr()
{

}
//*****************DISPLAY********************
void display()
{

}
``````

this is SJN in one class and its running,,,

``````#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int s,t[20],temp,n,x[20],w[20],i,j,c,d,b[20];
float average;
clrscr();
printf("Enter The Job  3-5:");

scanf("%d",&n);
if(n<=5){
if(n==3){
printf("Enter the Time of Job A,B,C:\n");
}
if(n==4){
printf("Enter the Time of Job A,B,C,D:\n");
}
if(n==5){
printf("Enter the Time of Job A,B,C,D,E:\n");
}
for(i=1;i<=n;i++)
{
scanf("%d",&b[i]);
x[i]=i;
}
for(i=1;i<=n-1;i++)
{
for(j=i+1;j<=n;j++)
{
if(b[i]>b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
s=x[i];
x[i]=x[j];
x[j]=s;
}
}
}
c=0;
d=0;
for(i=1;i<=n;i++)
{
w[i]=w[i-1]+b[i-1];
t[i]=b[i]+t[i-1];
w[1]=0;
t[1]=b[1];
c+=w[i];
d+=t[i];
}
average=(float)d/n;
printf("Job List\n");
for(i=1;i<=n;i++)
{
if(x[i]==1)
printf("A");
if(x[i]==2)
printf("B");
if(x[i]==3)
printf("C");
if(x[i]==4)
printf("D");
if(x[i]==5)
printf("E");
else
printf("");
printf("\n");
}
for(i=1;i<=n;i++)
{
if(i==n){
printf("Time Consumed: %d\n",t[i]);
printf("Average Turn-Around Time: %.2f",average);
}
}
}
else{
printf("Invalid Input");
}

getch();
}
``````

and the FCFS running too

``````#include<stdio.h>
#include<conio.h>
int main(){
char char2,char3,char4,char5,char6,char7,char8,char9;
int input,num1,num2,num3,num4,num5;
int out1,out2,out3,out4,out5,out6;
clrscr();
printf("Enter How Many Jobs 4-5: ");
scanf("%d",&input);
if(input==4){
printf("Enter The 1st Job:\n");
scanf("%s",&char7);
printf("Enter The 2nd Job:\n");
scanf("%s",&char6);
printf("Enter The 3rd Job:\n");
scanf("%s",&char2);
printf("Enter The 4th Job:\n");
scanf("%s",&char4);
printf("Enter The Time Job %c, Job %c, Job %c And Job %c :\n",char7,char6,char2,char4);
scanf("%d%d%d%d",&num1,&num2,&num3,&num4);
out1=num1+num2;
out2=num3+out1;
out3=num4+out2;
out4=num1+out1+out2+out3;
out5=out4/4;
printf("All Job Executed: %c %c %c %c \n",char7,char6,char2,char4);
printf("Time Consumed: %d \n",out3);
printf("Average Turn-Around Time: %d",out5);
}
if(input==5){
printf("Enter The 1st Job:\n");
scanf("%s",&char9);
printf("Enter The 2nd Job:\n");
scanf("%s",&char6);
printf("Enter The 3rd Job:\n");
scanf("%s",&char8);
printf("Enter The 4th Job:\n");
scanf("%s",&char4);
printf("Enter The 5th Job:\n");
scanf("%s",&char3);
printf("Enter The Time Job %c, Job %c, Job %c, Job %c And Job %c :\n",char9,char6,char8,char4,char3);
scanf("%d%d%d%d%d",&num1,&num2,&num3,&num4,&num5);
out1=num1+num2;
out2=num3+out1;
out3=num4+out2;
out4=num5+out3;
out5=num1+out1+out2+out3+out4;
out6=out5/5;
printf("All Job Executed: %c %c %c %c %c\n",char9,char6,char8,char4,char3);
printf("Time Consumed: %d ",out4);
printf("Average Turn-Around Time: %d",out6);
}

getch();
return 0;
}
``````

What input are you typing in?
What did you expect to see on the screen?
What did you actually see on the screen?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.