Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

8 Apr 2013

PROGRAM TO COUNT TOTAL NUMBER OF POSITIVE AND NEGATIVE ELEMENTS IN A MATRIX AND PRINT THEM IN C++


#include<iostream.h>
#include<conio.h>
void main()
{   clrscr();
 int a[10][10];
 int i, j, n, m;
 int x[100],y[100],pos=0,neg=0;
 cout<<"enter no of rows\n";
 cin>>n;
 cout<<"enter no of colomn\n";
 cin>>m;
 cout<<"enter the values of matrix\n";
 for(i=0;i<n;i++)
  {
   for(j=0;j<m;j++)
    {
     cout<<"a["<<i+1<<"]["<<j+1<<"]:= ";
     cin>>a[i][j];
    }

  }
 cout<<"matrix u have entered is"<<endl;
 for(i=0;i<n;i++)
  {
   for(j=0;j<m;j++)
    {
     cout<<"\t"<<a[i][j];
    }
    cout<<endl;
  }
  for(i=0;i<n;i++)
  {
   for(j=0;j<m;j++)
    {
     if(a[i][j]>=0)
      {
       x[pos]=a[i][j];
       pos++;
      }
     else
       {
        y[neg]=a[i][j];
        neg++;
       }
    }
  }
  cout<<"total positive elements are= "<<pos<<endl;
  cout<<"positive elements are"<<endl;
  for(i=0;i<pos;i++)
   {
    cout<<x[i]<<endl;
   }
  cout<<"total neg elements are= "<<neg<<endl;
  cout<<"neg elements are"<<endl;
  for(i=0;i<neg;i++)
   {
    cout<<y[i]<<endl;
   }
getch();
}
==OUTPUT==


No comments:

Post a Comment