Tuesday 15 June 2010

C Programming - Max steps in array, shows more than max -



C Programming - Max steps in array, shows more than max -

i writing piece of software , got problem. seek do, go through array, of elements can 1 or 0, , write out maximum steps can perform given point in array. rule people can step 1 or more steps if it's same number. let's array looks this: 1,0,0,0,0,1,1,1,0 start beginning, should able step once, after 1 0, , can't alter numbers while stepping, when turn comes again. if start sec element, step 1, or 4 steps. now, want write out maximum amount of steps current player can step, reason, shows max step + 1.

each variable of int type. tomb = array, j,max_lepes initializes 0

#include <stdio.h> #include <stdlib.h> int main() { int tomb[200]={1,0,1,1,1,0,0,1,1,0,1}; // fo tomb int max_lepes,akt_pos,j,i,game_type=0; printf("valasszon jatek tipust (1 ember vs szamitogep, 2 ember vs ember): "); scanf("%d", &game_type); if (game_type==1) { } else if (game_type==2) { // aktualis tomb kiirasa printf("\naz aktualis szin tomb: "); (i=0; i<11; ++i) { printf("%d ", tomb[i]); } i==0; // max lepesek kiirasa max_lepes == 0; akt_pos == 0; (j=0; j<11; ++j) { if (tomb[j]==tomb[j+1]) { max_lepes=max_lepes+1; } else { printf("\nmaximum lepesek szama= %d", max_lepes); break; } } } else { printf("rosz szamot irt be, kerem irjon 1-et vagy 2-et."); } homecoming 0; }

max_lepes == 0; akt_pos == 0;

should be

max_lepes = 0; akt_pos = 0;

c arrays max

No comments:

Post a Comment