You are on page 1of 3

LAB PROGRAMS

IMPLEMENT FILE SYSTEM

#include<stdio.h>

int main(int argc,char *argv[])

FILE *f1,*f2;

char c;

f1=fopen(argv[1],"r");

f2=fopen(argv[2],"w");

while((c=getc(f1))!=EOF)

putc(c,f2);

}
-----------------------------------------
MULTIPLICATION PROGRAM

#include<stdio.h>
main()
{
int m,n;
printf("enter two numbers");
scanf("%d%d",&m,&n);
printf("%d",sum(m,n));
}
int sum(int m,int n)
{
if(n==1)
return m;
else
return(m+sum(m,n-1));
}

----------------------------------
USING SEMAPHORES

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int main(void)
{
key_t key;
int semid;
struct sembuf sb = {0, -1, 0}; /* set to allocate resource */

/* grab the semaphore set created by seminit.c: */


if ((semid = semget(IPC_PRIVATE, 1, 0)) == -1) {
perror("semget");
exit(1);
}
printf("Press return to lock: ");
getchar();
printf("Trying to lock...\n");
if (semop(semid, &sb, 1) == -1) {
perror("semop");

------------------------------------------

NETWORK COMMUNICATION .C

#include<stdio.h>
int main()
{
system("write 11a51f0002");
system("who");
}

SEARCH.C

a=(-1 2 -3 4 -5 6 -7 8 90)
echo "elments before sorting"
echo ${a[*]}
echo "perfomring sorting"
for((i=0;i<=${#a[*]};i++))
do
h=${a[i]}
echo "i value is "$h
for((j=`expr $i + 1 `;j<${#a[*]};j++))
do
t=${a[j]}
echo "j value is"$t
if [ $h -ge $t ]
then
temp=${a[$i]}
a[$i]=${a[$j]}
a[$j]=$temp
fi
done
done
echo "elments after sorting"
echo ${a[*]}
echo "min"
echo ${a[0]}
echo "max"
echo ${a[${#a[*
}]}

--------------------------------

You might also like