0% found this document useful (0 votes)
5 views4 pages

lab4omnarainrai

The document contains two C programs: the first program calculates the transpose of a matrix based on user input for rows and columns, and the second program represents a sparse matrix using triplet representation. Both programs include user prompts for input and display the results accordingly. The code is structured with loops for input and output operations.

Uploaded by

om0405202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

lab4omnarainrai

The document contains two C programs: the first program calculates the transpose of a matrix based on user input for rows and columns, and the second program represents a sparse matrix using triplet representation. Both programs include user prompts for input and display the results accordingly. The code is structured with loops for input and output operations.

Uploaded by

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

Om Narain Rai

2100290110106
DSUC lab
Group B2

1)Program to find the transpose of a matrix.


#include <stdio.h>

int main() {

// Write C code here

int arr[5][5],a,b;

printf("enter the rows and column\n");

scanf("%d%d",&a,&b);

printf("enter the elements\n");

for(int i=0;i<a;i++)

for(int j=0;j<b;j++)

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

for(int i=0;i<a;i++)

for(int j=0;j<b;j++)

printf("%d ",arr[i][j]);

printf("\n");

printf("transpose matrix\n");

for(int i=0;i<b;i++)

{
for(int j=0;j<a;j++)

printf("%d ",arr[j][i]);

printf("\n");

return 0;

2)Program for triplet representation of a sparse matrix


// Online C compiler to run C program online

#include <stdio.h>

int main() {

// Write C code here

int c=0,k=0;

int arr[5][5];

int a,b;

printf("enter the no of rows and columns\n");

scanf("%d%d",&a,&b);

printf("enter the elements\n");


for(int i=0;i<a;i++)

for(int j=0;j<b;j++)

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

for(int i=0;i<a;i++)

for(int j=0;j<b;j++)

if(arr[i][j]!=0)

c++;

int arr2[3][c];

for(int i=0;i<a;i++)

for(int j=0;j<b;j++)

if(arr[i][j]!=0)

arr2[0][k]=i;

arr2[1][k]=j;

arr2[2][k]=arr[i][j];

k++;

printf("solution of sparse matrix:\n");

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

for(int j=0;j<c;j++)

printf("%d ",arr2[i][j]);

printf("\n");

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy