Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

86
Visualizações
how do i Convert the C to javascript

This is important question to ask, how do i Convert C code to Javascript? Please help me this for my Project

#include <stdio.h>

int MAXSIZE = 8;
int stack[8];
int top = -1;

int isempty()
{
    if (top == -1)
        return 1;
    else
        return 0;
}
int isfull()
{
    if (top == MAXSIZE)
        return 1;
    else
        return 0;
}

int peek()
{
    return stack[top];
}

int pop()
{
    int data;
    if (!isempty()) {
        data = stack[top];
        top = top - 1;
        return data;
    }
    else {
        printf("Could not retrieve data, Stack is empty.\n");
    }
}

int push(int data)
{
    if (!isfull()) {
        top = top + 1;
        stack[top] = data;
    }
    else {
        printf("Could not insert data, Stack is full.\n");
    }
}

int main()
{
    // push items on to the stack
    push(3);
    push(5);
    push(9);
    push(1);
    push(12);
    push(15);

    printf("Element at top of the stack: %d\n", peek());
    printf("Elements: \n");

    while (!isempty()) {
        int data = pop();
        printf("%d\n", data);
    }
    printf("Stack full: %s\n", isfull() ? "true" : "false");
    printf("Stack empty: %s\n", isempty() ? "true" : "false");
    return 0;
}

The Output is:

Element at top of the stack: 15
Elements:
15
12
1 
9 
5 
3 
Stack full: false
Stack empty: true
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

A little help.

 C               | JS
-----------------|------------------
 int x;          | var x;
-----------------|------------------
 int xs[n];      | var xs = [];
-----------------|------------------
 printf(...)     | console.log(...)
-----------------|------------------
 int f (int x) { | function f (x) {
   ...           |   ...
   return y;     |   return y;
 }               | }

The remaining syntax from your post is almost identical in C and JS.

Press F12 in your browser (Chrome or Firefox) and have some fun with JavaScript ​in the "Console" tab, it's a good starting point :-) For example, copy paste the below code into the browser console and press ENTER.

function add (a, b) {
  return a + b;
}
console.log("1 + 1 =", add(1, 1));
add(1, 2);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda