Author

Author- Ram Ranjeet Kumar
Showing posts with label C PROGRAMS AND PROJECTS. Show all posts
Showing posts with label C PROGRAMS AND PROJECTS. Show all posts

Wednesday, July 10, 2019

Rainbow Program in C

Rainbow Program in C

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<snap.h>
void main()
{
int gdriver = DETECT,gmode;
int x,y,i;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
x=getmaxx()/2;
y=getmaxy()/2;
for(i=30;i<200;i++)
{
delay(100);
setcolor(i/10);
arc(x,y,0,180,i-10);
}
capture("C:\\TC\\Capture\\Capture1.jpg");
getch();
}

SJF SCHEDULING ALGORITHM IN C

#include<stdio.h>

void main()
{
    int p[5],b[5],i,j,temp=0,w=0,t=0,wt=0,tt=0;
    float ATT,AWT;

    printf("\n\n\tSJF SCHEDULING ALGORITHM\n");
    printf("\n\tEnter The Burst Time For 5 Processs:\n");
    for(i=1;i<=5;i++)
    {
        printf("\n\tEnter The Burst Time For Process P%d: ",i);
        scanf("%d",&b[i]);
        p[i]=i;
    }

    for(i=1;i<=5;i++)
    {

        for(j=1;j<=5;j++)
        {
            if(b[i]<b[j])
            {
                temp=b[i];
                b[i]=b[j];
                b[j]=temp;

                temp=p[i];
                p[i]=p[j];
                p[j]=temp;
            }
         }
 }
    printf("\n\n\tPRO\tBT\tWT\tTT\n");
    printf("===========================================================\n");
    {
        for(i=1;i<=5;i++)
        {
            t=w+b[i];
            printf("\n\n\tP%d\t%d\t%d\t%d",p[i],b[i],w,t);
            tt=tt+t;
            wt=wt+w;
            w=w+b[i];
       }
       printf("\n\n\tTotal Waiting Time: %d ",wt);
       printf("\n\tTotal T-Time: %d ",tt);

    }
  AWT=wt/5;
  ATT=tt/5;
  printf("\n\n\tAverage Waiting Time: %f ",AWT);
  printf("\n\tAverage T-Time: %f \n\n",ATT);
}

Thursday, October 18, 2018

SCAN,C-SCAN,LOOK DISK SCHEDULING PROGRAM USING SWITCH CASE IN C

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

int main()
{
    int a[100],b[100],i,j,ls,n,ds,temp,ip,ip1;
int hm,mv,lv,min[100],max[100],flag=0;
    char ch;
    printf("Enter The Size of Disk: ");
    scanf("%d",&ds);
    printf("Enter The Length of String: ");
    scanf("%d",&ls);
    printf("\nEnter the String between 0 & %d:\n",ds);
    for(i=1;i<=ls;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]<ds)
        {
            b[i]=a[i];
        }
        else
        {
            printf("\n\t*****Enter String is Larger Than Disk Size.*****\n");
            printf("\t*****Please Hit The ENTER and do process again.*****\n\n");
            exit(0);
        }
    }
     printf("Enter The Initial Position: ");
     scanf("%d",&ip);
     if(ip<ds)
    {
    ip1=ip;
    }
    else
    {
        printf("\n\t*****Initial Position is Out Of Disk Space.*****\n ");
        printf("\t*****Please Hit The ENTER and do process again.*****\n\n");
        exit(0);
    }
 
    printf("\nPress L/l for left direction or lower value.");
printf("\nPress R/r/H/h for right direction or higher value.");
printf("\nEnter The Direction of scheduling.===================> ");
scanf("%s",&ch);
    printf("\nSorted String is: " );
    for(i=1;i<=ls;i++)
    {
      for(j=i+1;j<=ls;j++)
      {
          if(b[i]>=b[j])
          {
              temp=b[i];
              b[i]=b[j];
              b[j]=temp;
          }
      }
      printf("%d ",b[i]);
    }
 
    mv=b[1];
    for(i=2;i<=ls;i++)
    {
    if(mv<b[i])
    {
    mv=b[i];
}
}
//printf("\nLarger value=%d",mv);
lv=b[1];
    for(i=2;i<=ls;i++)
    {
    if(lv>b[i])
    {
    lv=b[i];
}
}
//printf("\nLowest value=%d\n\n",lv);

for(i=1;i<=ls;i++)
{
if(b[i]<ip1)
{
min[i]=b[i];
flag++;
}
else
{
max[i]=b[i];
}
}

 
//
//switch case statement
printf("\n==============================================================");
printf("\n\tMake Your Choice.");
printf("\n\tPress 1 for SCAN Disk sceduling Head Movement.");
printf("\n\tPress 2 for C-SCAN Disk sceduling Head Movement.");
printf("\n\tPress 3 for LOOK Disk sceduling Head Movement.");
printf("\n\tPress 4 for Exit.");
printf("\n\tEntered Choice===>\t");
scanf("%d",&n);
printf("\n==============================================================");
switch(n)
{
case 1:
if(ch=='l'||ch=='L')
{
hm=ip1+mv;
printf("\n\t\ttotal Head Movement=%d",hm);

}
else if(ch=='r'||ch=='R'||ch=='h'||ch=='H')
{
hm=((ds-ip1)+(ds-lv));
printf("\n\t\ttotal Head Movement=%d",hm);

}
else
{
printf("\n\tEntered direction is invalid.\n");
exit(0);
}
break;

case 2:
if(ch=='l'||ch=='L')
{
hm=(ip1+ds+(ds-max[0]));
printf("\n\t\ttotal Head Movement=%d",hm);

}
else if(ch=='r'||ch=='R'||ch=='h'||ch=='H')
{
hm=((ds-ip1)+(ds)+min[flag]);
printf("\n\t\ttotal Head Movement=%d",hm);

}
else
{
printf("\n\tEntered direction is invalid.\n");
exit(0);
}
break;

case 3:
if(ch=='l'||ch=='L')
{
hm=((mv-ip1)+(mv-lv));
printf("\n\t\ttotal Head Movement=%d",hm);

}
else if(ch=='r'||ch=='R'||ch=='h'||ch=='H')
{
hm=((ip1-lv)+(mv-lv));
printf("\n\t\ttotal Head Movement=%d",hm);

}
else
{
printf("\n\tEntered direction is invalid.\n");
exit(0);
}
break;

case 4:
exit(0);
break;

default:
printf("\n\n\t\t****Wrong Choice Selected by User***\n");

}
printf("\n\n\tCoded By-Ram Ranjeet Kumar\n\n");
 return 0;
}
Ram Ranjeet Kumar- college-St.Xavier College Ranchi

Thursday, April 19, 2018

Rainbow Program in C

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<snap.h>
void main()
{
int gdriver = DETECT,gmode;
int x,y,i;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
x=getmaxx()/2;
y=getmaxy()/2;
for(i=30;i<200;i++)
{
delay(100);
setcolor(i/10);
arc(x,y,0,180,i-10);
}
capture("C:\\TC\\Capture\\Capture1.jpg");
getch();
}