//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
This is a directive, not a question.
http://www.assignmentsclub.com/
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.
#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();
printf("%s",per>50?:"pass",per<50?:"fail");
#include
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; }
i cant write
wap to print all the arnstrong no. between 100&1000
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/
ring me and ill explain - 086 22222222222222227 ring me