answersLogoWhite

0

#include <stdio.h>

#include <conio.h>

#include <alloc.h>

#define MAX1 3

#define MAX2 3

#define MAXSIZE 9

#define BIGNUM 100

struct sparse

{

int *sp ;

int row ;

int *result ;

} ;

void initsparse ( struct sparse * ) ;

void create_array ( struct sparse * ) ;

int count ( struct sparse ) ;

void display ( struct sparse ) ;

void create_tuple ( struct sparse *, struct sparse ) ;

void display_tuple ( struct sparse ) ;

void addmat ( struct sparse *, struct sparse, struct sparse ) ;

void display_result ( struct sparse ) ;

void delsparse ( struct sparse * ) ;

void main( )

{

struct sparse s[5] ;

int i ;

clrscr( ) ;

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

initsparse ( &s[i] ) ;

create_array ( &s[0] ) ;

create_tuple ( &s[1], s[0] ) ;

display_tuple ( s[1] ) ;

create_array ( &s[2] ) ;

create_tuple ( &s[3], s[2] ) ;

display_tuple ( s[3] ) ;

addmat ( &s[4], s[1], s[3] ) ;

printf ( "\nResult of addition of two matrices: " ) ;

display_result ( s[4] ) ;

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

delsparse ( &s[i] ) ;

getch( ) ;

}

/* initialises structure elements */

void initsparse ( struct sparse *p )

{

p -> sp = NULL ;

p -> result = NULL ;

}

/* dynamically creates the matrix */

void create_array ( struct sparse *p )

{

int n, i ;

/* allocate memory */

p -> sp = ( int * ) malloc ( MAX1 * MAX2 * sizeof ( int ) ) ;

/* add elements to the array */

for ( i = 0 ; i < MAX1 * MAX2 ; i++ )

{

printf ( "Enter element no. %d:", i ) ;

scanf ( "%d", &n ) ;

* ( p -> sp + i ) = n ;

}

}

/* displays the contents of the matrix */

void display ( struct sparse s )

{

int i ;

/* traverses the entire matrix */

for ( i = 0 ; i < MAX1 * MAX2 ; i++ )

{

/* positions the cursor to the new line for every new row */

if ( i % MAX2 0 )

printf ( "\n" ) ;

printf ( "%d\t", * ( s.result + i ) ) ;

}

}

/* deallocates memory */

void delsparse ( struct sparse *p )

{

if ( p -> sp != NULL )

free ( p -> sp ) ;

if ( p -> result != NULL )

free ( p -> result ) ;

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

How do you add two matrices using Linux shell script?

write ashell script to add awo matrix using array.


How do you write and draw an algorithm in flowchart for Add 2 and 4 and print the sum?

2+4


What must be true in order to add matrices?

They must have the same dimensions.


How do you add fractions in matrices?

The usual rules of addition of fractions apply.


Write an algorithm that accept five numbers add them together and output the results instruct?

dont know use google instead dumb


Is there any benefit in a C plus plus program to add two matrices?

No.


Flow chart for addition of two matrices?

For the resulting matrix, just add the corresponding elements from each of the matrices you add. Use coordinates, like "i" and "j", to loop through all the elements in the matrices. For example (for Java; code is similar in C):for (i = 0; i


Write an algorithm for perfect number or not?

1. Get any no. 2. Find it factors. 3. Add its factor. 4. If sum of its factors is equal to itself then it is a perfect no. otherwise not


How do you add matrices?

You add matrices by adding their respective terms - e.g. the element in the first row and sixth column of the sum is the sum of the elements in the addends' first rows and sixth columns. Wikipedia has a nice example of matrix addition that I linked below.


Write the algorithm for the conversion of temperature from Celsius scale to Fahrenheit scale?

To convert temperature from Celsius to Fahrenheit: Multiply the Celsius temperature by 9/5. Add 32 to the result from step 1 to get the Fahrenheit temperature. Algorithm: Fahrenheit = (Celsius * 9/5) + 32.


What is algorithm and what are its characteristics?

An "algorithm" is simply a method to solve a certain problem. For example, when you use the standard method you learned in school to write down two numbers, one beneath the other, then add them, you are using an algorithm - a method that is known to give correct results in this particular case.


Can a matrix of 4x5 be added with a matrix with dimensions of 5x3?

No. You can only add matrices of the same size.