Skip to main content

Posts

Showing posts with the label 8th semester

Mutex variable using pthread in C programming

#include <stdio.h> #include <stdlib.h> #include <pthread.h> void *functionC(); pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; int counter = 0; main() { int rc1, rc2; pthread_t thread1, thread2; /* Create independent threads each of which will execute functionC */ if( (rc1=pthread_create( &thread1, NULL, &functionC, NULL)) ) { printf("Thread creation failed: %d\n", rc1); } if( (rc2=pthread_create( &thread2, NULL, &functionC, NULL)) ) { printf("Thread creation failed: %d\n", rc2); } /* Wait till threads are complete before main continues. Unless we */ /* wait we run the risk of executing an exit which will terminate */ /* the process and all threads before the threads have completed. */ pthread_join( thread1, NULL); pthread_join( thread2, NULL); exit(0); } void *functionC() { pthread_mutex_lock( &mutex1 ); counter++; pri...

Write a program of greeting using pthread in C programming

#include <stdio.h> #include <string.h> #include <sys/types.h> #include <pthread.h> #include <stdlib.h> #include <unistd.h> #define MAX_THREAD 1000 typedef struct { int id; int nproc; }parm; char message[100]; /* storage for message */ pthread_mutex_t msg_mutex = PTHREAD_MUTEX_INITIALIZER; int token = 0; void* greeting(void *arg) { parm *p = (parm *) arg; int id = p->id; int i; if (id != 0) { /* Create message */ while (1) { pthread_mutex_lock(&msg_mutex); if (token == 0) { sprintf(message, "Greetings from process %d!", id); token++; pthread_mutex_unlock(&msg_mutex); break; } pthread_mutex_unlock(&msg_mutex); sleep(1); } /* Use strlen+1 so that '\0' gets transmitted */ } else { /* my_rank == 0 */ for (i = 1; i nproc; i++) { while (1) { pthread_mutex_lock(&msg_mutex); if (token == 1) { printf("%s\n", message); ...

Write a program of Hello World using pthread in C programming

#include #include #include #define NUM_THREADS 5 void *PrintHello(void *threadid) { long tid; tid = (long)threadid; printf("Hello World! It's me, thread #%ld!\n", tid); pthread_exit(NULL); } int main(int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc; long t; for(t=0;t OUTPUT Compile & run(linux terminal): gcc -o Pthread_Hello_world pthread_hello_world.c -lpthread ./Pthread_Hello_world OUTPUT: In main: creating thread 0 In main: creating thread 1 Hello World! It's me, thread #0! In main: creating thread 2 Hello World! It's me, thread #1! In main: creating thread 3 Hello World! It's me, thread #2! In main: creating thread 4 Hello World! It's me, thread #3! Hello World! It's me, thread #4!

Prim’s Algorithm For Minimum Spanning Tree In C Programming

#include #include #define size 20 #define infi 9999 void prim(int L[][size],int node) { int T[size],i,j,k; int min_dist,v1,v2,total=0; for(i=1;i OUTPUT ---------------------------------------------------- PRIM`s MINIMUM SPANNING TREE ALGORITHM ---------------------------------------------------- Enter Number of nodes in the Graph:7 Enter Number of Edges in the Graph:12 --------Enter edges and length---------- Enter edge in form {v1,v2}:1 2 Enter Length from 1 to 2:1 Enter edge in form {v1,v2}:1 4 Enter Length from 1 to 4:4 Enter edge in form {v1,v2}:2 3 Enter Length from 2 to 3:2 Enter edge in form {v1,v2}:2 4 Enter Length from 2 to 4:6 Enter edge in form {v1,v2}:2 5 Enter Length from 2 to 5:4 Enter edge in form {v1,v2}:3 6 Enter Length from 3 to 6:6 Enter edge in form {v1,v2}:3 5 Enter Length from 3 to 5:5 Enter edge in form {v1,v2}:4 5 Enter Length from 4 to 5:3 Enter edge in form {v1,v2}:4 7 Enter Length from 4 to 7:4 Enter edge in form {v1,v2}:...

Matrix Multiplication in C Programming

#include int main() { int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[10][10], multiply[10][10]; printf("Enter the number of rows and columns of first matrix\n"); scanf("%d%d", &m, &n); printf("Enter the elements of first matrix\n"); for (c=0;c OUTPUT Enter the number of rows and columns of first matrix 3 3 Enter the elements of first matrix 1 2 3 4 5 6 7 8 9 Enter the number of rows and columns of second matrix 3 3 Enter the elements of second matrix 9 8 7 6 5 4 3 2 1 Product of entered matrices:- 30 24 18 84 69 54 138 114 90

Bubble Sort in C Programming

#include< stdio.h> #include<conio.h> void display(int*,int); void bubble_sort(int*,int); void main() { int i,*a,n; clrscr(); printf("\n Enter number of element you want:"); scanf("%d",&n); for(i=0;i < n;i++) { printf("\n Enter element[%d]:",i); scanf("%d",&a[i]); } printf("\n------------------------------------------"); printf("\n Elements before sorting:"); display(a,n); printf("\n------------------------------------------"); bubble_sort(a,n); printf("\n------------------------------------------"); printf("\n Elements after sorting:"); display(a,n); printf("\n------------------------------------------"); getch(); } void bubble_sort(int *a,int n) { int pass,i,temp; for(pass=0;pass<= n-1;pass++) { for(i=0;i< n-pass-1;i++) { if(a[i]>=a[i+1]) { temp=a[i]; a[i]=a[i+1]; a[i+1]=temp; } } printf("\...

8th Semester books

BUSINESS INTELLIGENCE & DATA MINING Data Mining Concepts and Techniques , J. Han, M. Kamber 2nd Edition(Text book) Solution Manual for Data Mining Concept and Techniques by J Han Paulraj Ponnian, “Data Warehousing Fundamentals”, John Willey PARALLEL PROCESSING Introduction to Parallel Computing, Ananth Grama, Anshul Gupta, George Karypis, Vipin Kumar, By Pearson Publication(Text book) DISTRIBUTED SYSTEMS Distributed Computing, Fundamentals, Simulations and Advanced topics, 2nd Edition, Hagit Attiya and Jennifer Welch, Wiley India(2nd Text book) *i have not uploaded any books, i got the links from google.com i am not responsible for any copy right materials 

Quick Sort Using Divide an Conquer

#include #include #define MAX 50 //int pivotpoint; void display(int[MAX],int); void Quick_sort(int[MAX],int low,int high); int pivot(int[MAX],int,int); void main() { int i,T[MAX],n; clrscr(); printf("\n Enter number of element you want:"); scanf("%d",&n); for(i=0;i low) { pivotpoint=pivot(T,low,high); Quick_sort(T,low,pivotpoint-1); Quick_sort(T,pivotpoint+1,high); } } int pivot(int T[MAX],int low,int high) { int i,j; int pivotitem,temp; pivotitem=T[low]; i=low; j=high; while(i pivotitem) j--; if(i OUTPUT Enter number of element you want:10 Enter element[0]:56 Enter element[1]:33 Enter element[2]:2 Enter element[3]:90 Enter element[4]:67 Enter element[5]:45 Enter element[6]:43 Enter element[7]:77 Enter element[8]:56 Enter element[9]:2 ------------------------------------------------------------------------------------ Elements before sorting: 56 33 2 90 67 45 43 77 56 2 ---------------------...