C++ program that input rectangular matrix A nxm (integer) and finds out the indexes of most occurred element and counts how many times he occurs.

I just can't do it :(

Recommended Answers

All 6 Replies

You have to. :) It's a challenge. All you need is a little motivation, Google and peanuts. *tap at the back*

But I gotta do it till tommorow! I don't have time!!!

>>I don't have time!!!
Such is the life of a programmer -- we all feel that way frequently, especially when we don't start coding until just before the program is due to be shipped. That's when you load up on peanutbutter & jelly sandwitches, then go for a 24-hour day at your computer.

Write your program in very small steps. What's the first thing you have to do? write the main() function and create an array! write that and get it to compile cleanly before going on to the next step.

Do in small steps and you will soon have your program written.

Post back here with the code you have written and with more specific questions. Crying will not help.

the post above really touch'd me!

#include <iostream.h>


int count,a[2][2]={0,2,2,3}; //primary matrix


void main() {
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
if(a[i][j]==a[i++][j++])
count++;
cout<<a[i][j]<<count;
}

your coding style needs a lot of improvement.
1) add { and } for clarity and to tell the compiler what lines go inside the loop. The way I placed it below is how your compiler would have treated it, which is probably not what you intended.

2) iostream.h is obsolete. Current c++ standard header files do not have extensions. But if you are using an ancient compiler such as Turbo C then you don't have any other choice but the use those obsolete header files. If you can you should get a current, free compiler.

#include <iostream>
using namespace std;


int count,a[2][2]={0,2,2,3}; //primary matrix


int main() {
    for(int i=0;i<5;i++)
    {
          for(int j=0;j<5;j++)
          {
                if(a[i][j]==a[i++][j++])
                       count++;
          }
      }
     cout<<a[i][j]<<count;
}

And of course, int main returns an exit code. For good coding practice. :)

#include <iostream>
using namespace std;


int count,a[2][2]={0,2,2,3}; //primary matrix


int main() {
    for(int i=0;i<5;i++)
    {
          for(int j=0;j<5;j++)
          {
                if(a[i][j]==a[i++][j++])
                       count++;
          }
      }
     cout<<a[i][j]<<count;

     return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.