A c++ program to take the size and components of an Array from user and return the reversed Array

I have written this code that should take the size and components of the array from the user and then return the reverse of the Array but not able to identify and fix the error.
My best guess is that the while loop is causing trouble, but I am not sure.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

// function to reverse given array
void reverseArray(int arr(), int start, int end){

while (start<=end){
    int temp = arr(start);
    arr(start) = arr(end);
    arr(end) = temp;


// function to print given array
void printArray(int arr(), int size){
   for (int i = 0; i < size; i++)
   cout << arr(i) << " ";

int main() {
    int n;
    cin >> n;
    int mainarray() = {n} ; 
    n = sizeof(mainarray);

    for (int i=0; i<n; i++) {
        cin >> mainarray(i);

reverseArray(mainarray , 0, n-1);
printArray(mainarray ,n);

    return 0;

data structures – Reverse An Array whats wrong with this type of code?

data structures – Reverse An Array whats wrong with this type of code? – Computer Science Stack Exchange

unity – Instantiate from two values, each in separate array

I have a problem with Instantiating GameObjects from floats in arrays, which I have to merge into one Vector2(or Vector3), I have only two values on arrays:

GameObject = somePrefab
float() = value1
float() = value2

First I have to combine it to Vector then Instantiate as many prefabs as the combined Vector number is…

Can anybody help me with how to merge these floats into Vector and instantiate?

Cognito Forms: Selecting Individual Items From an Array

I have created an array, using the .Split() functionality, I would like to now reference each item (it I believe) in that array, specifically.

How do I achieve that?

The rest of this you don’t need to read, but I’ll try to provide more information.

I am now going to use an example of something that I might like to do, this is not literally all I want to do.

So. Let’s say a user has input the following data in to the ‘Inputta‘ field:


Now, in the ‘Arraya‘ field, I have:


Let’s say I would like to select the “ddd” entry in that array, how would I do that?

I’ve tried using the .Where() functionality, eg: “.Where(ItemNumber = 4)“, but even if that did work (it doesn’t), it would be no use for if I need to be iterative.

I’ve tried to play with the .Select() functionality, but that’s not helpful, either, as I can’t find decent information on how it even works.

So, on to that iterative tip, to build on this example, I have a secondary requirement of the form, which is to pick an item from the array from an incremented integer.

We’ll imagine I know how to increment an integer, and have that information already, either in a separately generated .Split() field, or as an integer calculation in a Repeating Section.

How would I use the integer to find the array entry in the ‘Arraya‘ field?

Basically, how would I select item 1 (from the second array), then item 2, etc?

This isn’t a separate question, I’m just explaining further the requirement.

As an addendum, I’d love to know how to create an array of incremental integers leading to a pre-determined max number. 😉

For the record, I have StartPaged this thoroughly.

  1. I can’t find a full reference chart for the functions available anywhere online.
  2. The list on CF only lists a subset of the available functions (for example, the .Select() array functionality is not listed)
  3. Everywhere else appears to handle other specific functions.

None of that is stated to cast any disdain anywhere, purely to indicate that I have looked, perhaps my StartPage Fu is just not that strong. Either way, apologies for asking here.

compile – Improving large array manipulation

I am doing an iterative program, which uses large arrays/vectors and where the output of one round is used as an input for the next steps but works slowly when dimensions are bigger.
In brief, we create firstly the complex matrix s (dimension dos x dos) using SparseArray

    s = SparseArray({{i_, i_} :> 1. + I, Band({2, 1}) -> 2., 
    Band({1, 2}) -> 2., Band({dos + 1, 1}) -> 2.0, 
    Band({1, dos + 1}) -> 2.0}, {dos*dos, dos*dos}, 0.);

And initial condition


And finally, we do the iterative steps following some conditions/rules related to which position in the array is used

    lr = Table(i, {i, 1 + dos, dos*dos - dos, dos});
    ll = Table(i, {i, dos + dos, dos*dos - dos, dos});
    lt = Table(i, {i, 1, dos, 1});
    lb = Table(i, {i, dos*dos - dos + 1, dos*dos, 1});
    lll = Sort(Join(lr, ll, lt, lb)); (*rules*)
    Do(f = SparseArray({{i_} :> 
       If(MemberQ(lll, i), 
        0, -2.0*u1((i - 1)) - 2.0*u1((i + 1)) - 2.0*u1((i + dos)) - 
         2.0*u1((i - dos)) + (1.+I)*u1((i)))}, {dos*dos});
    u1 = LinearSolve(s, f);, {j, 1, steps, 1})

This takes around 15 sec on my computer but with increasing dimensions, the time needed grows quickly. I noticed that applying LinearSolve is not slow, but creating the array f is where almost all the time is consumed. Is there a way to create f more efficiently? I tried to use Compile but not good results. Thanks in advance

asymptotics – Searching in sorted array with $O(log n)$

Recently been practicing some recent exams, there was a problem I could not comprehend the given answer, the question is as follows:

Suppose array $A(1..n)$ consist of $n$ distinct integers that is
sorted in ascending order, then How many of below problems could be
solved in $O(log n)$?

and there were three statements;

  • Find an $i$ index so that $A(i)= i $
  • Find an $i$ index so that $A left lfloor{i}right rfloor = 3i +2$
  • Find an $i$ index so that $A(i)= 4i^{2} + 3i + 5$

The answer sheet stated as one statement is true, Also there was no clue on which statement is true.

What is my issue?

So I think the first and second statements could be true, since the array is sorted then we can use Binary search with $O(log n)$ to find the element with index $i$, also the first two statements are linear, thus I think that’s what the question wants, If it’s not then I don’t know what the question exactly wants, any explanation would be handful.

database – How to access array element?

I have the following array:
(1) => DrupalnodeEntityNode Object
(in_preview) =>
(values:protected) => Array
(nid) => Array
(x-default) => 1
(vid) => Array
(x-default) => 19
(type) => Array
(x-default) => mak
(uuid) => Array
(x-default) => d3129b72-d115-458e-9a5e-28f23ce5d9a4

How can I access nid from this?

Trash value em um array do C

Eu estou fazendo um programa cuja função é importar os valores de um arquivo .dat e colocá-los dentro de um vetor. Para isso, fiz o seguinte código:

void Import_vec(int tamanho,const char caminho(),float * vetor,int chave)

    FILE *arquivo = fopen(caminho,"r");

    for(int i = 0;i<tamanho;i++)
        fscanf(arquivo, "%ft", &vetor(i));
        if(chave == 1)
            printf("%fn",vetor(i)); // Caso seja 1, os valores serão impressos no terminal

Na saída aparecem todos os valores corretos, mas ao terminar de imprimir o último valor aparece um trash value (valor gigantesco que não está no arquivo).



Antes de usar fscanf() eu usei fgets(), strtok e strtod para ler a linha, separar os valores com base em um token e converter a string para um float, mas ainda assim dava o mesmo problema. O que pode ser? O que ocasiona isso? Como posso evitar? Outro problema: o tamanho do vetor é 10, mas com o trash value o vetor acaba tendo 11 valores. Como? (Para alocar o vetor usei malloc(10*sizeof(float))).
Caso precisem de informações adicionais, O código completo é:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

float *Alloc_vec(int n){
    float *v = malloc(n*sizeof(float));
    if(v == NULL)
    return v;

float **Alloc_array(int n, int m){
    float **matriz;
    matriz = malloc(n*sizeof(float *));
    if(matriz == NULL)
    for(int i = 0;i<n;i++){
        matriz(i) = malloc(m*sizeof(float ));
        if(matriz(i) == NULL){
    return matriz;

void Import_vec(int tamanho,const char caminho(),float * vetor,int chave)

    FILE *arquivo = fopen(caminho,"r");

    for(int i = 0;i<tamanho;i++)
        fscanf(arquivo, "%ft", &vetor(i));
        if(vetor(i) >10)
            vetor(i) = 0;
        if(chave == 1)

void Import_array(int n, int m ,const char caminho(),float ** matriz,int chave)
    FILE *arquivo = fopen(caminho,"r");
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            fscanf(arquivo, "%f ", &matriz(i)(j));
            if(chave == 1)
                printf("%f ",matriz(i)(j));



int main(){
    int Ni=20,Nj=30,Nk=10;
    float *u = Alloc_vec(Nk);
    float *v = Alloc_vec(Nj);
    float **A = Alloc_array(Ni,Nk);
    float **B = Alloc_array(Nk,Nj);
    char caminho_u() = "u_vec.dat";
    char caminho_v() = "v_vec.dat";
    char caminho_A() = "A_array.dat";
    char caminho_B() = "B_array.dat";

    //Definição de C
    float **C = Alloc_array(Ni,Nj);
    for(int i = 0;i<Ni;i++)
        for(int j=0;j<Nj;j++)
            C(i)(j) = 0;
            for(int k = 0;k<Nk;k++)
                C(i)(j) += A(i)(k)*B(k)(j);
    //Definição de s
    float *s = Alloc_vec(Nk);
    for(int i = 0;i<Ni;i++)
        s(i) = 0;
        for(int j=0;j<Nk;j++)
            s(i) += A(i)(j)*u(j);

    //Definição de r
    float *r = Alloc_vec(Nj);
    for(int i = 0;i<Ni;i++)
        r(i) = 0;
        for(int j=0;j<Nj;j++)
            r(i) += C(i)(j)*v(j);

        float numero = r(i);
    float z=0;
    for(int i = 0;i<Ni;i++)
   // printf("%f",z);
    for(int i = 0;i<Ni;i++)
    for(int i = 0;i<Nk;i++)
    for(int i = 0;i<Ni;i++)
    return 0;

php – how can make looping array to be one array with simple code

i want make my looping data in one array without index. i had solve it with code above but i think it so crowd and not simple

this my code

$data = array();
while($dt = $this->db->fetchAssoc($res_weight)){
    $data() = array_values($dt);
$datas = json_encode($data);
$datas = str_replace("(","",$datas);
$datas = str_replace(")","",$datas);
$datas = '('.$datas.')';
$datas = json_decode($datas);

how can i make this code more simply then this code

array – Llamada GET siempre me trae una colección, ¿cómo hacer para traer 1 recurso por separado?

No puedo hacer que la respuesta que hago a una API sea “única”, en vez de devolverme un sólo recurso me trae una colección y necesito ver sólo un recurso.

  1. En mi controlador PlayVideosController hago una llamada hacia una API en donde le agrego una variable $id al parámetro de mi función, esta busca en la API la columna de _id, luego la guardo en una variable que guarda un array.
    public function thps4($id)
        $thps4Videos = Http::get('http://thvid-api.herokuapp.com/videos/game/THPS4/$id/1')->json();
        $thps4Video = $thps4Videos(0);
        return view ('videos.thps4', compact('thps4Video'));
  1. Esta información la paso a un componente de Livewire en donde realizo un forelse, y dentro tengo un <a href="">, aquì le paso el $key para poder seleccionar un recurso, esto como resultado me genera una URL asi: http:://thpsvido.com/videos/thps4/4
<div wire:init="loadTHPS4">

        @forelse ($thps4Results as $key => $thps4)
            <div wire:key="results-{{ $thps4('_id') }}">
                <img src="https://es.stackoverflow.com/{{ $thps4("Thumbnail') }}">
                        <a class="relative bottom-4" href="videos/thps4/{{ $key }}">

                        <p class="text-sm font-semibold ml-14">
                            {{ $thps4('Title') }}
            @foreach (range(1,6) as $thumbnail)
                <div wire:key="empty-{{ $thumbnail }}">
  1. Al hacer clic en el href uno es redireccionado a otra página en donde existe un elemento de tipo <video>, y utilizando una librería, VideoJS hago que se carge un video de Youtube. Es en las propiedades de la librería en donde escribo la dirección, y aquí en la dirección: reemplazo el ID del video de youtube con la variable que tengo en mi controlador. Aquí, la variable de $key ya tiene que haber asociado la posición de un array, con la columna ID. Y esto debería de suceder para todas las arrays, obteniendo un video con un ID diferente.
    <div class="pt-20 h-full w-screen">

            x-data="{close: true}"
            <p class="text-sm text-gray-500">
              Mute is enabled by default, sorry for the inconveniences
                x-on:click="close = false"
                class="text-green-500 text-sm cursor-pointer"
        </div> {{-- inconveniences message --}}

    <!-- videojs -->
    <script src="https://vjs.zencdn.net/7.10.2/video.min.js"></script>
    <script src="{{ asset ('/js/Youtube.min.js') }}"></script>
        var player = videojs('vid1', { 
            "techOrder": ("youtube"), 
            "sources": ({ "type": "video/youtube", 
            "src": "http://www.youtube.com/watch?v={{ $thps4Video('ID') }}"}),
            "fluid": true,
            "autoplay": true
        player.ready(function() {
            setTimeout(function() {
            }, 2000);

Dependiendo de la URL, un video diferente se debería de cargar cada vez que se hace clic, ya que si la URL es la siguiente http:://thpsvido.com/videos/thps4/4 entonces deberíamos de cargar sólamente un video, y ese sería el que esté en la posición 4. Otro ejemplo, si la dirección es la siguiente: http:://thpsvido.com/videos/thps4/5, entonces debería de devolver el de la posición 5.

No importa cual sea el número que aparezca en la URL, por ejemplo, puede ser: http://thvid-api.herokuapp.com/videos/game/THPS4/$id/2, aquí se cargan 2 videos debería de ver sólamente 1, el de la posición 2.

Si hago un dd($thps4Videos) en mi función y le doy clic al video que sea, siempre me devuelve el mismo video en el array.

Un array dentro de la colección tiene estas columnas:

array:1 (▼
  0 => array:8 (▼
    "_id" => "605a43ea667cd39060f435ac"
    "Title" => "THPS4 Rewind: Summer Of 2003 Unreleased (Edited by Maxfli)"
    "Game" => "THPS4"
    "ID" => "Qxd7D1KN1No"
    "Thumbnail" => "https://i.ytimg.com/vi_webp/Qxd7D1KN1No/maxresdefault.webp"
    "newduration" => "00:22:53"
    "category" => "gameplay"
    "updatedAt" => "2021-04-12T17:45:27.167Z"

No tengo ningun error en cuanto a excepciones o mensajes de error.

Estoy utilizando una librería Javascript llamada VideoJS, versión 7.10.2, estoy usando Mozilla Firefox en Windows 10. También estoy utilizando la extensión de Youtube de esta misma librería.
VideoJS: https://github.com/videojs/video.js
Youtube extension: https://github.com/videojs/videojs-youtube

La API recolecta estos datos de Youtube.

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123