mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
cin accepts only one variable at a time & fixed cpplint
This commit is contained in:
parent
139964d325
commit
2def9abcc2
@ -1,41 +1,40 @@
|
|||||||
/*A sparse matrix is a matrix which has number of zeroes greater than (m*n)/2,
|
/** @file
|
||||||
where m and n are the dimensions of the matrix.*/
|
* A sparse matrix is a matrix which has number of zeroes greater than
|
||||||
#include <iostream>
|
* \f$\frac{m*n}{2}\f$, where m and n are the dimensions of the matrix.
|
||||||
using namespace std;
|
*/
|
||||||
|
|
||||||
int main()
|
#include <iostream>
|
||||||
{
|
|
||||||
|
int main() {
|
||||||
int m, n;
|
int m, n;
|
||||||
int counterZeros = 0;
|
int counterZeros = 0;
|
||||||
cout << "Enter dimensions of matrix (seperated with space): ";
|
|
||||||
cin >> m >> n;
|
std::cout << "Enter dimensions of matrix (seperated with space): ";
|
||||||
|
std::cin >> m;
|
||||||
|
std::cin >> n;
|
||||||
|
|
||||||
int a[m][n];
|
int a[m][n];
|
||||||
cout << "Enter matrix elements:";
|
std::cout << "Enter matrix elements:";
|
||||||
cout << "\n";
|
std::cout << "\n";
|
||||||
|
|
||||||
// reads the matrix from stdin
|
// reads the matrix from stdin
|
||||||
for (int i = 0; i < m; i++)
|
for (int i = 0; i < m; i++) {
|
||||||
{
|
for (int j = 0; j < n; j++) {
|
||||||
for (int j = 0; j < n; j++)
|
std::cout << "element? ";
|
||||||
{
|
std::cin >> a[i][j];
|
||||||
cout << "element? ";
|
|
||||||
cin >> a[i][j];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// counts the zero's
|
// counts the zero's
|
||||||
for (int i = 0; i < m; i++)
|
for (int i = 0; i < m; i++) {
|
||||||
{
|
for (int j = 0; j < n; j++) {
|
||||||
for (int j = 0; j < n; j++)
|
if (a[i][j] == 0) counterZeros++; // Counting number of zeroes
|
||||||
{
|
|
||||||
if (a[i][j] == 0)
|
|
||||||
counterZeros++; //Counting number of zeroes
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// makes sure the matrix is a sparse matrix
|
// makes sure the matrix is a sparse matrix
|
||||||
if (counterZeros > ((m * n) / 2)) //Checking for sparse matrix
|
if (counterZeros > ((m * n) / 2)) // Checking for sparse matrix
|
||||||
cout << "Sparse matrix";
|
std::cout << "Sparse matrix";
|
||||||
else
|
else
|
||||||
cout << "Not a sparse matrix";
|
std::cout << "Not a sparse matrix";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user