Easy program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2005
Posts: 49
Reputation: ohyeah is an unknown quantity at this point 
Solved Threads: 1
ohyeah ohyeah is offline Offline
Unverified User

Easy program

 
0
  #1
Aug 21st, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 169
Reputation: murderotica is an unknown quantity at this point 
Solved Threads: 2
murderotica's Avatar
murderotica murderotica is offline Offline
Junior Poster

Re: Easy program

 
0
  #2
Aug 21st, 2008
You have to. It's a challenge. All you need is a little motivation, Google and peanuts. *tap at the back*
An Avalanche In D Minor
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 49
Reputation: ohyeah is an unknown quantity at this point 
Solved Threads: 1
ohyeah ohyeah is offline Offline
Unverified User

Re: Easy program

 
0
  #3
Aug 21st, 2008
But I gotta do it till tommorow! I don't have time!!!
Last edited by ohyeah; Aug 21st, 2008 at 7:52 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,577
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1486
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Easy program

 
0
  #4
Aug 21st, 2008
>>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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 49
Reputation: ohyeah is an unknown quantity at this point 
Solved Threads: 1
ohyeah ohyeah is offline Offline
Unverified User

Re: Easy program

 
0
  #5
Aug 21st, 2008
the post above really touch'd me!
  1. #include <iostream.h>
  2.  
  3.  
  4. int count,a[2][2]={0,2,2,3}; //primary matrix
  5.  
  6.  
  7. void main() {
  8. for(int i=0;i<5;i++)
  9. for(int j=0;j<5;j++)
  10. if(a[i][j]==a[i++][j++])
  11. count++;
  12. cout<<a[i][j]<<count;
  13. }
Last edited by Ancient Dragon; Aug 21st, 2008 at 8:53 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,577
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1486
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Easy program

 
0
  #6
Aug 21st, 2008
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;
}
Last edited by Ancient Dragon; Aug 21st, 2008 at 9:03 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 169
Reputation: murderotica is an unknown quantity at this point 
Solved Threads: 2
murderotica's Avatar
murderotica murderotica is offline Offline
Junior Poster

Re: Easy program

 
0
  #7
Aug 21st, 2008
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;
}
Last edited by murderotica; Aug 21st, 2008 at 11:57 pm.
An Avalanche In D Minor
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC