Kontera

Wednesday, November 30, 2011

Transpose of a Sparse Matrix using array


/************************************************************
* Filename: sparse_matrix.c
* Description: To find transpose of a sparse matrix using array
* Author: Sarju S
* Date: 25-Nov-2011
*************************************************************/

#define MAX_TERMS 100
#include
typedef struct{
int col;
int row;
int value;
}sparse_matrix;
sparse_matrix a[MAX_TERMS],b[MAX_TERMS];
int input_matrix[10][10];

void create_sparse(int row, int col){
int i,j,k=1,count=0;
a[0].row=row;
a[0].col=col;
for(i=0;i
for(j=0;j
if(input_matrix[i][j]!=0)
{
count++;
a[k].row=i;
a[k].col=j;
a[k].value = input_matrix[i][j];
k++;
}
a[0].value = count;
}

void print_sparse(sparse_matrix matrix[]){
int i;
for(i=0;i<=matrix[0].value;i++)
printf("%d\t%d\t%d\n",matrix[i].row,matrix[i].col,matrix[i].value);
}

void transpose_sparse(){
int currentb=1,n,i,j;
n=a[0].value; /* total number of elements*/
b[0].row = a[0].col;
b[0].col = a[0].row;
b[0].value = a[0].value;
for(i=0;i
for(j=1;j<=n;j++)
if(a[j].col==i) 
{
/* Element is in the current column add it to b*/
b[currentb].row = a[j].col;
b[currentb].col = a[j].row;
b[currentb].value = a[j].value;
currentb++;

}
}


void main(){
int row,col,i,j;
printf("\nEnter the order of the matrix:");
scanf("%d%d",&row,&col);
printf("\nEnter the elements\n");

/*Read the matrix*/
for(i=0;i
for(j=0;j
scanf("%d",&input_matrix[i][j]);

/*Create sparse matrix*/
create_sparse(row,col);
printf("The Given Matrix is\n");
for(i=0;i
{
for(j=0;j
printf("%d\t",input_matrix[i][j]);
printf("\n");
}

/*Print sparse matrix*/
printf("\nThe Sparse Matrix is\n");
print_sparse(a);

/* Call transpose function*/
transpose_sparse();

/*Print transpose of sparse matrix*/
printf("\nThe transpose of Sparse Matrix is\n");
print_sparse(b);


}


OUTPUT


sjcet@sjcet-laptop:~$ gcc sparse_matrix.c
sjcet@sjcet-laptop:~$ ./a.out

Enter the order of the matrix:6 6

Enter the elements
15 0 0 22 0 -15
0 11 3 0 0 0
0 0 0 -6 0 0
0 0 0 0 0 0
91 0 0 0 0 0
0 0 28 0 0 0
The Given Matrix is
15 0 0 22 0 -15
0 11 3 0 0 0
0 0 0 -6 0 0
0 0 0 0 0 0
91 0 0 0 0 0
0 0 28 0 0 0

The Sparse Matrix is
6 6 8
0 0 15
0 3 22
0 5 -15
1 1 11
1 2 3
2 3 -6
4 0 91
5 2 28

The transpose of Sparse Matrix is
6 6 8
0 0 15
0 4 91
1 1 11
2 1 3
2 5 28
3 0 22
3 2 -6
5 0 -15


Polynomial Addition Using Array


/************************************************************
* Filename: pol_add_using_array.c
* Description: To add two polynomials using array
* Author: Sarju S
* Date: 24-Nov-2011
*************************************************************/
#include
#include
#define MAX_TERMS 100
typedef struct
{
float coef;
int expon; 
}polynomial;
polynomial terms[MAX_TERMS];P
int avail=0;

void attach(float coefficient, int exponent)
{

/* add new term to the polynomial */
if(avail>=MAX_TERMS) {
printf("Too many terms in the polynomial");
exit(EXIT_FAILURE);
}
terms[avail].coef = coefficient;
terms[avail++].expon = exponent;


}
void padd(int startA, int finishA, int startB, int finishB, int *startD, int *finishD)

/* add A(x) and B(x) to obtain D(x)*/
float coefficient;
*startD = avail;
while(startA<=finishA && startB<=finishB)
switch(compare(terms[startA].expon,terms[startB].expon)){

case -1: /* a expon < b expon */
attach(terms[startB].coef,terms[startB].expon);
startB++;
break;

case 0: /* equal exponents */
coefficient = terms[startA].coef + terms[startB].coef;
if(coefficient)
attach(coefficient,terms[startB].expon);
startA++;
startB++;
break;

case 1: /* a expon < b expon */
attach(terms[startA].coef,terms[startA].expon);
startA++;
}

/* add in remaining terms of A(x) */
for(;startA<=finishA; startA++)
attach(terms[startA].coef,terms[startA].expon);

/* add in remaining terms of A(x) */
for(;startB<=finishB; startB++)
attach(terms[startB].coef,terms[startB].expon);
*finishD = avail-1;
}

int compare(int expon1, int expon2)
{
if(expon1
else if(expon2
else return 0;
}

void pread(int no_ofterm, int *start, int *finish)
{
int i;
*start=avail;
printf("avail=%d",avail);
for(i=0;i
{
printf("\n Enter the coefficient and exponent:");
scanf("%f%d",&terms[avail].coef,&terms[avail].expon);
avail++;

}
*finish= avail-1;

}
void pprint(int start, int finish)
{ int i;
for(i=start;i<=finish;i++)
printf("%fX^%d+",terms[i].coef,terms[i].expon);
}

void main()
{
int no_ofterm,i,j;
int startA,finishA,startB,finishB,startD,finishD;
printf("\nEnter the number of terms in the first polynomial:");
scanf("%d",&no_ofterm);
pread(no_ofterm,&startA,&finishA);
finishA= avail-1;
printf("\nEnter the number of terms in the second polynomial:");
scanf("%d",&no_ofterm);
pread(no_ofterm,&startB,&finishB);
finishB= avail-1;
padd(startA,finishA,startB,finishB,&startD,&finishD);
printf("\nFirst Polynomial is\n");
pprint(startA,finishA);
printf("\nSecond Polynomial is\n");
pprint(startB,finishB);
printf("\nFinal Polynomial is\n");
pprint(startD,finishD);

}

Tuesday, May 31, 2011

Mg University B.Tech New University Examination Pattern

University Examination Pattern


PART A:
Short answer questions (one/two sentences)


All questions are compulsory. There should be at least one question from each module and not more than two questions from any module.(5 x 3 marks=15 marks)




PART B:
Analytical/Problem solving questions


Candidates have to answer five questions out of seven. There should be at least one question from each module and not more than two questions from any module.( 5 x 5 marks=25 marks)




PART C:
Descriptive/Analytical/Problem solving questions      
  

Two questions from each module with choice to answer one question.( 5 x 12 marks=60 marks)


 Maximum Total Marks: 100


CS010 608  Mini Project Evaluation

Internal Continuous Assessment (50 marks)
40% - Design and development (30% by guide and 10% by committee)
30% - Final result and Demonstration  (15% by guide and 15% by committee)          
20% - Report (10% by guide and 10% by committee)                                    
10% - Regularity in the class (by guide)

End Semester Examination (Maximum Marks-100)
20% -   Demonstration of mini project
50% -   Practical test connected with mini project
20% -   Viva voce
10% -   Project report