answersLogoWhite

0

//Write a C program to print the sum of a sparse matrix.(Data Structure)

#include

#include

int i,j,k,l,m,m1,m2,n1,n2,nz1=0,nz2=0,z1=0,z2=0,sm1[3][50],sm2[3][50],

a[100][100],b[100][100],sm3[3][50];

void main()

{

clrscr();

printf("\n\n\n\t\t FIRST MATRIX");

printf("\n\nENTER THE VALUE FOR ROW = ");

scanf("%d",&m1);

printf("\n\nENTER THE VALUE FOR COLUMN= ");

scanf("%d",&n1); clrscr();

printf("\n\nENTER THE VALUE FOR (%d*%d) MATRIX= ",m1,n1); for(i=0;inz1) printf("\n\n\nIT CAN CONVERT INTO SPARSE MATRIX\n"); else { printf("\n\nCAN'T CONVERT INTO SPARSE MATRIX\n"); exit(1); } //converting into sparse matrix printf("\n\nCONVERSION OF SPARSE MATRIX\n\n"); sm1[0][0]=m1; sm1[0][1]=n1; sm1[0][2]=nz1; k=1; for(i=0;inz2) printf("\n\n\nIT CAN CONVERT INTO SPARSE MATRIX\n"); else { printf("\n\nCAN'T CONVERT INTO SPARSE MATRIX\n"); exit(1); } //converting into sparse matrix printf("\n\nCONVERSION OF SPARSE MATRIX\n\n"); sm2[0][0]=m2; sm2[0][1]=n2; sm2[0][2]=nz2; l=1; for(i=0;i=m2&&n2) { sm3[0][0]=m1; sm3[0][1]=n1; sm3[0][2]=nz1+nz2; } else { sm3[0][0]=m2; sm3[0][1]=n2; sm3[0][2]=nz1+nz2; } k=1,l=1,m=1; while(nz1!=0&&nz2!=0) { if(sm1[k][0]==sm2[l][0]&&sm1[k][1]==sm2[l][1]) { sm3[k][0]=sm1[k][0]; sm3[k][1]=sm1[k][1]; sm3[k][2]=sm1[k][2]+sm2[k][2]; k++; l++; m++; nz1++; nz2++; } //printing of addition OS sparse matrix printf("\n\n\t\tADDTION OF SPARSE MATRIX IS\n\n"); for(i=0;i

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Write a program to print the sum of a sparse matrix?

This is a directive, not a question.


Write a program using iostreams to take as input two multi-dimensional arrays and print their sum as output Matrix Addition in Matrix format?

http://www.assignmentsclub.com/


Write a C program to find sum of 3 matrices?

matrix


Write a C program using dynamic memory allocation to find the sum of elements of a matrix?

Did you know that memory allocation is not needed to display the matrix? However, the C program is to find the sum of all the elements.


Write a C program to accept the elements of a 3 x 3 matrix and find its sum of the major diagonal elements The program should print the given matrix along with its sum of the major diagonal elements?

#include <stdio.h> #include <conio.h> void main() { int d[3][3] = { 1, 2, 6, 3, 8, 5, 5, 6, 7 }; int k = 0, j = 0; int sum1 = 0, sum2 = 0; for (j = 0; j < 3; j++) { for (k = 0; k < 3; k++) printf(" %3d", d[j][k]); printf("\n"); } for (j = 0; j < 3; j++) { sum1 = sum1 + d[j][j]; } k = 3 - 1; for (j = 0; j < 3; j++) { if (k >= 0) { sum2 = sum2 + d[j][k]; k--; } } printf("Sum of First diagonal= %d\n", sum1); printf("Sum of Second diagonal= %d", sum2); getch();


Write a c program using dynamic memory allocation function calloc to find sum of two matrices and also print the resultant matrix?

printf("%s",per>50?:"pass",per<50?:"fail");


Write a C Program to print sum of squares of odd numbers?

#include


How do you write c programs to read and print out matrix and find sum and max number?

To write a C program that reads a matrix, prints it, and calculates both the sum and the maximum number, you can start by declaring a 2D array for the matrix. Use nested loops to input the matrix elements from the user and to print them. During the input process, maintain a variable to track the sum of all elements, as well as another variable to find the maximum value. Finally, output the sum and the maximum value after the matrix has been fully processed. Here's a simple structure: #include <stdio.h> int main() { int rows, cols; printf("Enter number of rows and columns: "); scanf("%d %d", &rows, &cols); int matrix[rows][cols], sum = 0, max = -2147483648; // Initialize max to the smallest int printf("Enter the matrix elements:\n"); for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) { scanf("%d", &matrix[i][j]); sum += matrix[i][j]; if (matrix[i][j] > max) max = matrix[i][j]; } printf("Matrix:\n"); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) printf("%d ", matrix[i][j]); printf("\n"); } printf("Sum: %d\nMax: %d\n", sum, max); return 0; }


How do you write c program to perform sum of elements of matrix using pointers with functions?

i cant write


How do you solve this program wap to print sum of a digit of an inputed number?

wap to print all the arnstrong no. between 100&1000


Gw basic program to add first 7 even number?

5 CLS 10 REM PROGRAM TO ADD FIRST 7 EVEN NUMBERS 20 EV = 2 30 SUM = 0 35 PRINT "NUMBERS="; 40 FOR I = 1 TO 7 50 SUM = SUM + EV 55 PRINT EV; 60 EV = EV + 2 70 NEXT I 95 PRINT 80 PRINT "SUM="; SUM 90 END http://arnavguddu.6te.net/


How do you write a program that calculates the sum of the matrix elements given numbers?

ring me and ill explain - 086 22222222222222227 ring me