0 comments

IIS LAB C PROGRAMS


                                                           LINEAR SEARCH
#include<stdio.h>
main()
{
int i,n,pos=0,flag=0,key,a[20];
clrscr();
printf("\nenter the size of array:");
scanf("%d",&n);
printf("\nenter the elements of array:\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nenter the key element:\n");
scanf("%d",&key);
for(i=0;i<n;i++)
{
if(key==a[i])
{
flag=1;
pos=i;
break;
}
}
if(flag==1)
{
printf("\nsearch is successful:");
printf("\n%d is found at position %d",key,pos+1);
}
else
printf("\nkey element is not found");
getch();
}



                                                           BINARY SEARCH 

#include<stdio.h>
main()
{
int i,j,temp,n,low,mid,key,a[20],high;
clrscr();
printf("\nenter the no of elements:");
scanf("%d",&n);
printf("\nenter the elements of array:\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(j=1;j<n;j++)
{
for(i=1;i<n;i++)
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
printf("\nthe elements after sorting:\n");
for(i=1;i<=n;i++)
printf("%d\t",a[i]);
printf("\nenter the key element:");
scanf("%d",&key);
low=1;
high=n;
while(low<=high)
{
mid=(low+high)/2;
if(key==a[mid])
break;
else if(key>a[mid])
low=mid+1;
else
high=mid-1;
}
if(a[mid]==key)
{
printf("\nsearching is successful:");
printf("\n%d is found at position %d",key,mid);
}
else
printf("\n%d is not found in the array",key);
getch();
}



                                                              BUBBLE SORTING 


#include<stdio.h>
main()
{
int i,j,k,n,a[20],temp,swap=0;
clrscr();
printf("\nenter no of elements:");
scanf("%d",&n);
printf("\nenter the elements of array:\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(j=1;j<n;j++)
{
printf("\npass%d\n",j);
for(i=1;i<n;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
swap++;
}
for(k=1;k<=n;k++)
printf("%d\t",a[k]);
printf("\n");
}
}
printf("\nno of comparitions are %d",(n*(n-1))/2);
printf("\nno of swapings are %d",swap);
getch();
}



                                                            INSERTION SORT


#include<stdio.h>
main()
{
int i,j,k,n,a[20],temp,swap=0;
clrscr();
printf("\nenter no of elements:");
scanf("%d",&n);
printf("\nenter the elements of array:\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=2;i<=n;i++)
{
printf("\npass%d:\n",i-1);
for(j=1;j<i;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
swap++;
}
for(k=1;k<=n;k++)
printf("%d\t",a[k]);
printf("\n");
}
}
printf("\nno of comparisions are %d",(n*(n-1))/2);
printf("\nno of swapings are %d",swap);
getch();
}


                                                               SELECTION SORT 


#include<stdio.h>
main()
{
int i,j,k,l,m,n,a[20],temp,swap=0;
clrscr();
printf("\nenter no of elements:");
scanf("%d",&n);
printf("\nenter the elements of array:\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<n;i++)
{
printf("\npass%d:\n",i);
l=i;
m=0;
for(j=i+1;j<=n;j++)
{
if(a[l]>a[j])
{
l=j;
m=1;
}
if(j==n)
{
temp=a[i];
a[i]=a[l];
a[l]=temp;
if(m==1)
swap++;
}
}
for(k=1;k<=n;k++)
printf("%d\t",a[k]);
printf("\n");
}
printf("\nno of comparisions are %d",(n*(n-1))/2);
printf("\nno of swapings are %d",swap);
getch();
}



                                                           QUICK SORT 


#include<stdio.h>
#include<conio.h>
void qsort(int a[],int left,int right);
void swap(int *a,int *b);
int n,k=1;
void main()
{
int a[20],i;
clrscr();
printf("\n enter no of elements in a list");
scanf("%d",&n);
printf("\n enter elements in an array");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
qsort(a,0,n-1);
printf("\n elements after sorting");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
getch();
}
void qsort(int a[],int left,int right)
{
int i,j,pivot,m;
if(left<right)
{
i=left;
j=right;
pivot=left;
while(i<j)
{
while(a[i]<=a[pivot] && i<right)
i++;
while(a[j]>a[pivot])
j--;
if(i<j)
swap(&a[i],&a[j]);
printf("\n pass %d",k);
k++;
for(m=0;m<n;m++)
printf("%4d",a[m]);
}
swap(&a[pivot],&a[j]);
qsort(a,left,j-1);
qsort(a,j+1,right);
}
}
void swap(int *a,int *b)
{
int t;
t=*a;
*a=*b;
*b=t;
}



                                                            ADAM NUMBER


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,y=0,n,d=0,x;
clrscr();
printf(“Enter n:\n”);
scanf(“%d”,&n);
a=n*n;
printf(“Square of %d is %d”,n,a);
while(a>0)
{
c=a%10;
a=a/10;
y=y*10+c;
}
printf(“\nReverse is %d”,y);
x=sqrt(y);
printf(“\nSquare root %d”,x);
while(x>0)
{
b=x%10;
x=x/10;
d=d*10+b;
}
printf(“\nReverse values is %d”,d);
if(n==d)
printf(“\n%d is Adam number”,n);
else
printf(“\n%d is not Adam number”,n);
getch();
}



                                          MATRIX ADDITION,SUBTRACTION,TRANSPOSE 


#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int m,n,p,q,i,j,a[10][10],b[10][10],c[10][10];
clrscr();
printf("\n enter the order of 1st matrix:\n");
scanf("%d %d",&m,&n);
printf("\n enter the order of 2nd matrix:\n");
scanf("%d %d",&p,&q);
printf("\n enter the elements of matrix 1 :\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n enter the elements of matrix 2:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
if(m!=p||n!=q)
{
printf("\nadd and sub arant possible");
goto down;
}
/*finding sum*/
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n resultant matrix is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
/*transpose*/
down:
printf("\ntransposed matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d\t",a[j][i]);
}
printf("\n");
}
/*subtraction*/
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]-b[i][j];
}
}
printf("\nresultant matrix is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}



                                                                JOB SCHEDULING ALGORITHMS
1)FCFS:


#include<stdio.h>
main()
{
int i,n,a[20],w[20],k=1,tat=0;
clrscr();
printf("\nenter no of process:");
scanf("%d",&n);
printf("\nenter burst time for each process:\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\ngantt chart is:\n");
up:printf("-");
k++;
if(k<=8*n+1)
goto up;
printf("\n");
for(i=1;i<=n;i++)
printf("| p%d ",i);
printf("|\n");
k=1;
repeat:printf("-");
k++;
if(k<=8*n+1)
goto repeat;
printf("\n0");
for(i=1;i<=n;i++)
{
w[i]=tat;
printf("\t%d",tat=tat+a[i]);
}
printf("\nwaiting time is:\n");
for(i=1;i<=n;i++)
{
printf("%d\n",w[i]);
}
getch();
}



2)SJF(NON PRE-EMPTIVE)

#include<stdio.h>
main()
{
int i,j,n,a[20],b[20],temp,tat=0,k=1,w[20];
clrscr();
printf("\nenter no of process:");
scanf("%d",&n);
printf("\nenter burst time of each process:\n");
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
for(i=1;i<=n;i++)
{
a[i]=b[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;
}
}
printf("\ngantt chart is:\n");
up:printf("-");
k++;
if(k<=8*n+1)
goto up;
printf("\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(b[i]==a[j])
{
printf("| p%d ",j);
}
}
}
printf("|\n");
k=1;
repeat:printf("-");
k++;
if(k<=n*8+1)
goto repeat;
printf("\n0");
for(i=1;i<=n;i++)
{
w[i]=tat;
printf("\t%d",tat=tat+b[i]);
}
printf("\nwaiting time is:\n");
for(i=1;i<=n;i++)
printf("%d\n",w[i]);
getch();
}



3)PRIORITY(PRE-EMPTIVE):
#include<stdio.h>
main()
{
int i,j,l,a[20],b[20],p[20],s[20],o[20],n,temp;
clrscr();
printf("\nenter no of process:");
scanf("%d",&n);
printf("\nenter burst time:\n");
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
printf("\nenter priority order:\n");
for(i=1;i<=n;i++)
scanf("%d",&p[i]);
printf("\nenter arrival time:");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
s[i]=100;
for(i=1;i<=n;i++)
o[i]=a[i];
for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(o[j]==a[i])
{
s[j]=p[i];
for(l=1;l<=n;l++)
{
if(s[l]!=0)
{
if(s[j]>s[l])
j=l;
}
}
if(i<n)
b[j]=b[j]-(a[i+1]-a[i]);
if(i==n)
b[j]=0;
printf("\n%d",b[j]);
}
}
}
getch();
}



4)PRIORITY(NON PRE-EMPTIVE):


#include<stdio.h>
main()
{
int i,j,n,a[20],p[20],b[20],w[20],temp,tat=0,k=1;
clrscr();
printf("\nenter no of process:");
scanf("%d",&n);
printf("\nenter burst time for each process:\n");
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
printf("\nenter priority order of each process:\n");
for(i=1;i<=n;i++)
scanf("%d",&p[i]);
for(i=1;i<=n;i++)
a[i]=p[i];
for(i=1;i<=n-1;i++)
{
for(j=i+1;j<=n;j++)
if(p[i]>p[j])
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
printf("\ngantt chart is:\n");
up:printf("-");
k++;
if(k<=8*n+1)
goto up;
printf("\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(p[i]==a[j])
printf("| p%d ",j);
printf("|\n");
k=1;
repeat:printf("-");
k++;
if(k<=n*8+1)
goto repeat;
printf("\n0");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(p[i]==a[j])
{
w[j]=tat;
printf("\t%d",tat=tat+b[j]);
}
printf("\nwaiting time is:\n");
for(j=1;j<=n;j++)
printf("%d\n",w[j]);
getch();
}



5)ROUND ROBIN: 


#include<stdio.h>
main()
{
int b[20],w[20],i,n,tq,k,tat=0,count=0,j=1;
clrscr();
printf("\nenter time qauntum:");
scanf("%d",&tq);
printf("\nenter no of process:");
scanf("%d",&n);
printf("\nenter burst time:\n");
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
printf("\ngantt chart is:\n");
printf("\n");
repeat:for(i=1;i<=n;i++)
{
if(b[i]>0)
{
b[i]=b[i]-tq;
k=0;
up:if(b[i]<0)
{
b[i]++;
k++;
goto up;
}
if(k!=0)
tat=tat+(3-k);
if(k==0)
tat=tat+3;
printf("| p%d ",i);
w[count]=tat;
count++;
}
}
for(i=1;i<=n;i++)
{
if(b[i]!=0)
goto repeat;
}
printf("|\n");
ds:printf("-");
j++;
if(j<=8*count+1)
goto ds;
printf("\n0");
for(i=0;i<count;i++)
printf("\t%d",w[i]);
getch();
}



                                                                 PAGE REPLACEMENT ALGORITHMS: 
1)FIRST IN FIRST OUT:


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,j=0,n,a[50],frame[10],no,k,avail;
float pr,count=0;
clrscr();
printf("\nenter number of frames:");
scanf("%d",&no);
printf("\nenter number of memory reference strings:");
scanf("%d",&n);
printf("\nenter memory reference strings:");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(k=0;k<no;k++)
{
frame[k]=-1;
}
printf("ref string \t page frame\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
{
if(frame[k]==a[i])
{
avail=1;
}
}
if(avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
{
printf("%d\t",frame[k]);
}
}
printf("\n");
}
printf("\npage fault is %f",count);
pr=(count/n)*100;
printf("\npage fault rate is %f",pr);
getch();
}


0 comments

DSP OBSERVATIONS

Hai frnds:-)

All DSP observations(executed programs) are uploaded in this website(www.gprecece.blogspot.com).
So that we can easily rectify our errors in our notes.
SO guys make use of it:-)
0 comments

Reuniting

Hiii.. Frnds:-)
Der may b a "Chance Of Reuniting" old frnds, leturers, x-Students of our resþective Schools, Colla§es n batchmates at work places.. For more details Click Here
0 comments

MAT LAB

HERE IS A MATLAB TOOLBOX FOR U.....IT IS FOR QUICK REFERENCE....U CAN DOWNLOAD HERE....:"DOWNLOAD"
0 comments

AUTOBOTZ 8051

PRESENTATION ON AUTOBOTZ..BASIC CONCEPTS ON EMBEDDED 'C' AND 8051 MICROCONTROLLER...U CAN PREPARE MULTIFUNCTIONABLE ROBOT EASILY....FOR MORE INFORMATION "DOWNLOAD HERE"
0 comments

For Fests n Ppts

H¡¡¡¡ Frnds here is a website in which we can know where the fests n ppts r being conducted.. in al clgs al ovr India..>>> CLICK HERE
0 comments

8051 MICRO CONTROLLER

Hai fnds.....HERE  is a topic on INTRODUCTION TO 8051 MICRO CONTROLLER....(BY  D.R.SRINIVAS    Sir).....To watch or download  
0 comments

ADVANCED SYSTEM CARE PRO SOFTWARE

Hiii.....fnds....here is a software for u....u can scan and delete errors in your system...its very cool...TRY IT
                                                               DOWNLOAD
 
;