100% found this document useful (1 vote)
487 views

LAB (CSE 610) : Advance Computer Architecture

The document contains a lab report submitted by Neha Kapoor for the course Advanced Computer Architecture. The report includes 5 programs implementing various algorithms: 1) matrix multiplication, 2) Jacobi iteration method, 3) Gauss elimination method, 4) preorder tree traversal, and 5) fast Fourier transformation. For each program, the problem statement, solution code, and sample output are provided.

Uploaded by

Neha Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
487 views

LAB (CSE 610) : Advance Computer Architecture

The document contains a lab report submitted by Neha Kapoor for the course Advanced Computer Architecture. The report includes 5 programs implementing various algorithms: 1) matrix multiplication, 2) Jacobi iteration method, 3) Gauss elimination method, 4) preorder tree traversal, and 5) fast Fourier transformation. For each program, the problem statement, solution code, and sample output are provided.

Uploaded by

Neha Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

ADVANCED COMPUTER ARCHITECTURE

ADVANCE COMPUTER ARCHITECTURE

LAB
(CSE 610)

SUBMITTED TO: SUBMITTED BY:

MRS. MANJU ARORA NEHA KAPOOR

BTECH CSE(6TH SEM)

020117003
1
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

INDEX

S.NO PRACTICALS SIGN

1. Write a program to perform the multiplication of


two matrices.

2. Write a program to implement Jacobi iteration


method.

3. Write a program to implement Gauss elimination


method.

4. Write a program to implement pre-order


traversal in a binary tree.

5. Write a program to implement fast fourier


transformation.

PROGRAM 1: Write a program to perform the multiplication of two matrices.


2
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

SOLUTION:

#include <stdio.h>

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 < m ; c++ )

for ( d = 0 ; d < n ; d++ )

scanf("%d", &first[c][d]);

printf("Enter the number of rows and columns of second matrix\n");

scanf("%d%d", &p, &q);

if ( n != p )

printf("Matrices with entered orders can't be multiplied with each other.\n");

else

printf("Enter the elements of second matrix\n");

for ( c = 0 ; c < p ; c++ )

for ( d = 0 ; d < q ; d++ )

scanf("%d", &second[c][d]);
3
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

for ( c = 0 ; c < m ; c++ )

for ( d = 0 ; d < q ; d++ )

for ( k = 0 ; k < p ; k++ )

sum = sum + first[c][k]*second[k][d];

multiply[c][d] = sum;

sum = 0;

printf("Product of entered matrices:-\n");

for ( c = 0 ; c < m ; c++ )

for ( d = 0 ; d < q ; d++ )

printf("%d\t", multiply[c][d]);

printf("\n");

return 0;
4
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

OUTPUT

PROGRAM 2: Write a program to implement Jacobi iteration method

5
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

SOLUTION:

#include<stdio.h>

#include<conio.h>

#include<math.h>

float fx(float y,float z)

float x1; x1=4-2*y-3*z;

return x1;

float fy(float x,float z)

float y1;

y1=(8-5*x-7*z)/6;

return y1;

float fz(float x,float y)

float z1;

z1=(3-9*x-y)/2;

return z1;

void main()
6
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

int i,j,n;

float a1,b1,c1;

float a,b,c;

float ar[3][4],x[3];

clrscr();

printf("\nEnter the no. of Iteration :\n ");

scanf("%d",&n);

printf("\nEnter The initial value : \n");

scanf("%f %f %f",&a,&b,&c);

for(i=0;i<n;i++)

for(j=0;j<n;j++)

a1=fx(b,c);

b1=fy(a,c);

c1=fz(a,b);

a=a1;

b=b1;

c=c1;

printf("a1 = %f\n a2 = %f\n a3 = %f",a1,b1,c1);

getch();

OUTPUT
7
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

FOR 6TH ITERATION

FOR 5TH ITERATION

FOR 4TH ITERATION

PROGRAM 3: Write a program to implement Gauss elimination method

8
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

INPUT

#include<stdio.h>

void solution( int a[][20], int var );

int main()

int a[ 20 ][ 20 ], var, i, j, k, l, n;

clrscr();

printf( "\nEnter the number of variables:\n" );

scanf( "%d", &var );

for ( i = 0;i < var;i++ )

printf( "\nEnter the equation%d:\n", i + 1 );

for ( j = 0;j < var;j++ )

printf( "\nEnter the coefficient of x%d:\n", j + 1 );

scanf( "%d", &a[ i ][ j ] );

printf( "\nEnter the constant:\n" );

scanf( "%d", &a[ i ][ var] );

solution( a, var );
9
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

return 0;

void solution( int a[ 20 ][ 20 ], int var )

int k, i, l, j;

for ( k = 0;k < var;k++ )

for ( i = 0;i <= var;i++ )

l = a[ i ][ k ];

for ( j = 0;j <= var;j++ )

if ( i != k )

a[i][j] = (a[k][k]*a[i][j])-(l*a[k][j]);

printf( "\nSolutions:" );

for ( i = 0;i < var;i++ )

printf( "\nTHE VALUE OF x%d IS %f\n", i + 1, ( float ) a[ i ][ var ] / ( float ) a[ i ]


[ i ] );

10
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

OUTPUT

ENTER THE EQUATION VALUES :

11
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

SOLUTION:

12
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

PROGRAM 4: Write a program to implement pre-order traversal in a binary tree

INPUT

#include<stdio.h>

#include<conio.h>

typedef struct node

int data;

struct node *left;

struct node *right;

} node;

node *create()

node *p;
13
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

int x;

printf("Enter data(-1 for no node):");

scanf("%d",&x);

if(x==-1)

return NULL;

p=(node*)malloc(sizeof(node));

p->data=x;

printf("Enter left child of %d:\n",x);

p->left=create();

printf("Enter right child of %d:\n",x);

p->right=create();

return p;

void preorder(node *t)

if(t!=NULL)

printf(" %d",t->data);

preorder(t->left);

preorder(t->right);

14
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

void main()

node *root;

clrscr();

root=create();

printf("\nThe preorder traversal of tree is: ");

preorder(root);

getch();

OUTPUT

15
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

PROGRAM 5: Write a program to implement fast fourier transformation ?

INPUT

#include<iostream.h>

#include<conio.h>

#include<math.h>

#include<dos.h>

#include<complex.h>

#define pi 3.141592654

void main()

clrscr();

int i,x,y,j,k,j1;
16
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

float o,o1;

complex p,q,r,s,w,m,n,alpha,beta,gamma1[10],gamma2[10];

complex y1[10],b[10],a[10],c[10],d[10],gamma[10],u[10],b2[10];

cout<<"Enter the elements of the array(upto 8 inputs): "<<endl;

for(i=0;i<=7;i++)

cin>>a[i];

cout<<endl<<endl<<endl;

cout<<"INPUT SIGNAL: "<<endl<<endl;

for(i=0;i<=7;i++)

cout<<a[i]<<endl;

for(i=0;i<=3;i++)

b[i]=a[2*i];

for(i=4,j=3;i<=7,j>=0;i=i+1,j=j-1)

b[i]=a[i-j];

for(i=0;i<=1;i++)

c[i]=b[2*i];
17
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

for(i=2,j=1;i<=3,j>=0;i++,j--)

c[i]=b[i-j];

for(i=4,j=0;i<=5,j<=1;i++,j++)

c[i]=b[i+j];

for(i=6,j=1;i<=7,j>=0;i++,j--)

c[i]=b[i-j];

for(i=0;i<=6;i=i+2)

m=c[i];

n=c[i+1];

alpha=m+n;

beta=m-n;

b[i]=alpha;

b[i+1]=beta;

for(i=0;i<=4;i=i+4)

p=b[i];

q=b[i+1];
18
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

r=b[i+2];

s=b[i+3];

for(k=0+i,j1=0;k<=2+i,j1<=2;k=k+2,j1=j1+2)

o=cos((2*pi*j1)/4);

o1=sin((2*pi*j1)/4);

w=complex(o,-o1);

gamma[k]=p+real(w)*r;

for(k=1+i,j1=1;k<=3+i,j1<=3;k=k+2,j1=j1+2)

o=cos((2*pi*j1)/4);

o1=sin((2*pi*j1)/4);

w=complex(o,-o1);

gamma[k]=q+(w)*s;

cout<<endl<<endl<<endl<<endl;

cout<<"FFT OUTPUT:";

cout<<endl<<endl;

for(i=0;i<=7;i=i+1)

{ y1[i]=gamma[i];

} for(k=j1=0;k<=3,j1<=3;k++,j1++)

o=cos((2*pi*j1)/8);

o1=sin((2*pi*j1)/8);
19
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

w=complex(o,-o1);

gamma1[k]=y1[k]+w*y1[k+4];

for(k=j1=4;k<=7,j1<=7;k++,j1++)

o=cos((2*pi*j1)/8);

o1=sin((2*pi*j1)/8);

w=complex(o,-o1);

gamma1[k]=w*y1[k]+y1[k-4];

for(i=0;i<=7;i++)

b2[i]=gamma1[i];

cout<<b2[i]<<endl;}

getch();

OUTPUT

20
NEHA KAPOOR
B.TECH CSE 6TH Semester
ADVANCED COMPUTER ARCHITECTURE

21
NEHA KAPOOR
B.TECH CSE 6TH Semester

You might also like