I am writing a program to display the elements of an integer array in random order and deleting the called value. I am on the last phase and while printing the array the lower and upper limits of the array are being printed. #include <iostream> #include <math.h> #include <time.h> #include <stdio.h> #include <stdlib.h> using namespace ..

#### Category : matrix

I am trying too add every element in a int matrix so I can check if the player or computer wins. bool WinCondition(int Grid[10][10]) { int SumOfShips; for (int a = 0; a < 10; a++) { for (int b = 0; b < 10; b++) { SumOfShips += Grid[a][b] ; if (SumOfShips == 30) ..

In this function void ShipPlacement(int ShipCount, int Grid[8][8]) { int VerticalHorizontal = rand() % 2; //Randomly generates a number that will decide if the ship is placed horizontally or vertically int ShipLocalX = rand() % (8 – ShipCount) ; int ShipLocalY = rand() % (8 – ShipCount) ; //The X and Y co ords of ..

Consider a matrix of dimensions n*n, n being 3 13 5 22 31 27 11 4 32 11 13 75 22 52 15 2 31 If you every try to access and output an element from a collumn outside the matrix say v[0][-1] it gives you the value 0, but if you try to access ..

I would like to make a matrix or 2D array in C++, in which I could store multiple elements in one matrix element, like a set or linked list or a pointer. The matrix would look something like this: sample matrix I am curious if there is any given data structure I could use for ..

I am trying to get an input to a matrix by placing the whole thing as in a function outside of main (), as follows: void input_matrix(int row, int col){ std::vector<std::vector<int>> matrix; for (int m=0; m<row; m++){ for (int n=0; n<col; n++){ std::cin >> matrix[m][n]; } } return matrix; } somehow the compiler doesn’t like ..

int main() { char Grid[8][8] = { ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, }; int ShipCount = 1; while ( ShipCount < 6){ ShipPlacement(ShipCount, Grid[8][8]); ShipCount++; } ShowGrid(Grid[8][8]); return 0; } int ShipPlacement(int Shipcount, char Grid[8][8]) { srand(time(NULL)); int VerticalHorizontal = rand() % 2; //Randomly generates a number that will decide if the ..

int main() { //In battleshipplacement() I place a battleship on a 8*8 grid int Grid = battleshipplacement(); ShowGrid(Grid); return 0; } void ShowGrid(int Grid) { cout << ‘|’; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { cout << ‘ ‘ << Grid[x][y] << ..

int Grid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int BattleShipPlace = rand() % 7; for (int i = 0, n = 0; i < 10; ++i, ++n) { if (BattleShipPlace == i) { Grid[n] = 1; Grid[n + 1] = 1; Grid[n + 2] = 1; } } In ..

https://codingcompetitions.withgoogle.com/codejamio/round/0000000000050ece/0000000000050df7#problem #include <iostream> #include <bits/stdc++.h> #define ll long long ; #define fo(i,n) for(int i=0;i<n;i++) #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define ss(s) scanf("%s",s) using namespace std; int gcd(int a,int b){ if(a==0) return b ; if(b==0) return a ; if(a==b) return a; if(a>b){ return gcd(a-b,b); }else{ return gcd(a,b-a); } } int digit(int n ){ return floor(log10(n)+1); ..

## Recent Comments