Jump to content

user404 challenge #3


user404

Recommended Posts

problem 3:

find out from how many not falling sequences is the matrix made of

e.g.

4 32 5 1 2 6 7

answer 3

solution:


#include <stdio.h>

int main(void){
  int matrix[]={3,3,5,6,3,25,6,3,6,7,8,6}; //answer should be 5
  int counter=1;

  int i;
  for(i=1; i<sizeof(matrix)/sizeof(matrix[0]); i++){
    if(matrix[i-1]>matrix[i])
      counter++;
  }

  printf(" %d sequences\n", counter);

  return 0;
}

~
~
~
~

Link to comment
Share on other sites

Wow. That book really sucks. What a stupid way to pose a question and what a strange thing so assume the sequence 5, 4, 3, 2, 1 is 5 separate non-falling sequences as opposed to 1 continuously falling sequence.

Link to comment
Share on other sites

Now it might just be my grasp of the english language that is lacking here, but isn't a matrix a 2-dimensional array rather than 1?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...