Write a C program to determine a given matrix is a sparse matrix – IGNOU MCA Assignment 2017 – 18

By | November 23, 2017

MASTER OF COMPUTER APPLICATIONS
Course Code: MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/2017-18
Maximum Marks : 100

Write a program to find the largest element in an array using Recursion – IGNOU MCA Assignment 2017 – 18

Program:

#include<stdio.h>
void main()
{
int MATRIX[10][10];
int I,J,M,N;
int COUNT=0;
clrscr();
printf(“ENTER THE ORDER OF MATRIX\n”);
scanf(“%d %d”,&M,&N);
printf(“ENTER THE CO-EFFICIENTS OF MATRIX\n”);
for(I=0;I<M;I++)
{
for(J=0;J<N;J++)
{
scanf(“%d”,&MATRIX[I][J]);
if(MATRIX[I][J]==0)
{
COUNT++;
}
}
}
if(COUNT>((M*N)/2))
printf(“THE GIVEN MATRIX IS A SPARSE MATRIX\n”);
else
printf(“THE GIVEN MATRIX IS NOT A SPARSE MATRIX\n”);
printf(“THERE ARE %d NUMBERS OF ZEROS”,COUNT);
getch();
}

Code:

#include<stdio.h>
void main()
{
int MATRIX[10][10];
int I,J,M,N;
int COUNT=0;
clrscr();
printf("ENTER THE ORDER OF MATRIX\n");
scanf("%d %d",&M,&N);
printf("ENTER THE CO-EFFICIENTS OF MATRIX\n");
for(I=0;I<M;I++)
{
for(J=0;J<N;J++)
{
scanf("%d",&MATRIX[I][J]);
if(MATRIX[I][J]==0)
{
COUNT++;
}
}
}
if(COUNT>((M*N)/2))
printf("THE GIVEN MATRIX IS A SPARSE MATRIX\n");
else
printf("THE GIVEN MATRIX IS NOT A SPARSE MATRIX\n");
printf("THERE ARE %d NUMBERS OF ZEROS",COUNT);
getch();
}

Screen Shots:

C_program_Sparse_Matrix

C_program_Sparse_Matrix_Output