vbl_array_2d<double> ArraySum(const vbl_array_2d<double> &A1, const vbl_array_2d<double> &A2) { assert(A1.rows() == A2.rows()); assert(A1.cols() == A2.cols()); vbl_array_2d<double> SumArray(A1.rows(), A1.cols()); for(unsigned int r = 0; r < A1.rows(); r++) { for(unsigned int c = 0; c < A1.cols(); c++) { SumArray(r,c) = A1(r,c) + A2(r,c); } } return SumArray; }
int main() { int Array[DIMEN][DIMEN]; unsigned int i, j; for (i = 0; i < DIMEN; i++) Array[i][i] = -i; for (i = 0; i < DIMEN; i++) for (j = 0; j < DIMEN; j++) if (j != i) Array[i][j] = i+j; printf("Sum(Array[%d,%d] = %d\n", DIMEN, DIMEN, SumArray(Array, DIMEN, DIMEN)); return 0; }
int main(void) { ARRAY_INT_4_6 Array = { { { 1, 2, 3, 4, 5, 6 }, { 2, 3, 4, 5, 6, 7 }, { 3, 4, 5, 6, 7, 8 }, { 4, 5, 6, 7, 8, 9 } } }; int Total; Total = SumArray(&Array); printf("Total is %d\n", Total); return 0; }
int main() { int xPos = (XGRID - 1)/2; int yPos = YGRID - 2; int xBull = 0; int yBull = 0; int WallArr[XGRID]; InitializeArray(WallArr, 1, XGRID); int BulletCounter = XGRID * 2; char Player = 'X'; char Wall = '#'; char Bullet = '^'; char PInput; printf("Controls:\n\nW: Shoot\nA: Left\nD: Right\nEnter: Execute Move(s)\n"); printf("\nPress Enter to start.\n\n"); getchar(); system("cls"); while (1) { DrawGrid(XGRID, YGRID, xPos, yPos, xBull, yBull, Player, Wall, Bullet, WallArr); printf("\n"); if (SumArray(WallArr, XGRID) < 3) { printf("You Win!\n\n"); break; } else if (BulletCounter < 1) { printf("You Lose!\n\n"); break; } scanf("%c",&PInput); PInput = toupper(PInput); switch (PInput) { case 'W': xBull = xPos; ShootingGrid(XGRID, YGRID, xPos, yPos, xBull, yBull, Player, Wall, Bullet, WallArr); WallArr[xPos] = 0; BulletCounter--; break; case 'A': if (xPos > 1) xPos--; break; case 'D': if (xPos < XGRID - 2) xPos++; break; } system("cls"); } return 0; }
void ScoreAverage(person_t p[]){ int i; for(i=0;i<NUM_OF_PERSON;i++){ p[i].ave = SumArray(p[i].score)/NUM_OF_SUBJECT; } }