Most voted "algorithm" questions
An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when the problem is related to the design of an algorithm. Always use specific algorithm tags when the question is more directed to a specific type of algorithm.
Learn more…723 questions
Sort by count of
-
2
votes1
answer266
viewsInequality in C language
Data: Brutus is 1.84m and weighs 122kg and Olivia is 1.76m and weighs 45kg. IMC = peso/(altura*altura); IMC: 18,5 a 25 -----> Saudável I want to create an algorithm that prints how much MINIMAL…
-
2
votes2
answers2890
viewsLoop "for" inside another "for" (nested repetition)
I’d like to spare those 9 repeated lines in my code: for (int n1 = 1, n2 = 1; n2 < 11;){ Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//1 Console.Write(n1 + "x" + n2 + "=" + (n1 *…
-
2
votes1
answer3602
viewsElectronic voting systems in Java
I am making an electronic ballot box that register, list and the user can vote for the candidate, I can already register and list candidates, but how do I always count +1 in an attribute votes of…
-
2
votes1
answer2003
viewsLoop "for" counted odd number, even and average
I need to make a code that: List a number of numbers Inform if they are divisible by 3 and 5 Whether they are even or odd And then take the separate average of each (average of odd and average of…
-
2
votes2
answers212
viewsRecursive algorithm does not work
I have to solve an exercise, and it says: Do a procedure that receives an integer and positive n number. The procedure shall print all numbers in the range 0 to n which are divisible by 2 and 3…
-
2
votes1
answer95
viewsMergesort, problem of logic
Gentlemen, I’m having a problem with my Mergesort sorting algorithm, I feel the problem is in logic. Merge code: static void mergesort(int[] x,int inicio,int fim){ if(inicio<fim){ int meio;…
-
2
votes1
answer105
viewsApi for file organization similar to tree structure
I am developing a meeting module, which contains management of staves, the staves are organized as follows: 1. pauta c 1.1.pauta x 2. pauta v 2.1. pauta b 2.1.1. pauta y Each staff of this is a…
-
2
votes1
answer186
viewsWhat is the benefit of a classification algorithm being stable?
A classification algorithm (Sorting) is said to be stable if it maintains the relative order of the elements with equal keys. I think my question is, what is the benefit of maintaining this relative…
-
2
votes2
answers155
viewsAlgorithm with flow chart/diagram
Guys, I’m taking a course in logic and the following question has fallen: Draw up a block diagram to verify which products need to be purchased and the quantity to be purchased: Having the following…
-
2
votes1
answer79
viewsError in sorting numbers
Even numbers I managed to sort, only odd numbers I can’t sort. The memory address of the number appears. Link to the question: Even and Odd Here is my code: #include <stdio.h> int main(int…
-
2
votes1
answer156
viewsConvert java lambda predicates
I am trying to perform a model transformation using java lambda. Below follows a block of code that exemplifies what I want to do: public String translatePrimitivePredicate(){…
-
2
votes1
answer344
viewsJoin three similar codes into one
I am working with a table that shows the number of vacancies offered, candidates enrolled and enrolled in higher education courses. I want to make a program that allows the visualization of this…
-
2
votes0
answers250
viewsHelp with bicubic interpolation algorithm
I’m trying to implement the bicubic interpolation algorithm but I’m having a lot of difficulty with the correct interpolated values( is not related to taking the values of the original matrix but…
-
2
votes1
answer854
viewsSelect from time to time
I’m trying to ride a sql to check if there is any record between times informed but not leaving, I did some tests but unsuccessfully. For example, a bank record containing these two times, as…
-
2
votes2
answers312
viewsAsterisk tree algorithm *
I have a problem in an activity, the activity would be to make an asterisk tree of the type: * *** ***** but with my code for (int i = 0; i <= 5 ; i++) { for (int j = 0; j <= i; j++) {…
-
2
votes1
answer186
viewsDo irreversible operations exist?
In mathematics (therefore in programming) there are mathematical operations (+,-,*,/). But all the mathematical operations I know are perfectly reversible, for example, by dividing a number, I could…
-
2
votes4
answers1891
viewsSum of pairs typed interval
I am trying to do a function for summing even numbers in an interval. For example somaDosPares(6) resultado = 12, but always returns me the number of (). function somaDosPares(x){ let soma = 0;…
-
2
votes1
answer187
viewsIs there any way to round a negative value to zero in Visualg?
I wish it were always displayed Vida: 0 in the last block, even if the value is negative, without doing that "Gambiarra" that I did just below. Is there any function around vidaInimigo, without the…
-
2
votes1
answer807
viewsStable vs unstable sorting
What defines a stable sort algorithm? In this question has already been talked a little about what is stable and unstable ordering, but I still do not understand the advantage of using an unstable.…
-
2
votes2
answers103
viewsNegative print, it only prints the postives
Write a program that reads whole numbers from the standard input until a negative number is reported. At each reading the number read should be written in the standard output. n1 = int(input())…
-
2
votes2
answers58
viewsWhy do you think the higher value?
x=0 quantos=0 valor=int(input()) while valor>0: if valor>x: x=valor #Se aqui ele define o X pro valor inserido, por que ele armazena o maior número? #não deveria armazenar o último? quantos=1…
-
2
votes1
answer480
viewsDifference between Dictionaries and Lists/Arrays?
I am trying to understand the concept of each and its differences. I want to understand in which situations to use one or the other.
-
2
votes1
answer888
viewsThe sum of the N first prime numbers
Write a program that reads a non-negative integer and print the sum of the N first prime numbers. I am not able to add the N first prime numbers but add up to the prime number typed. If I type 5 for…
-
2
votes1
answer61
viewsHow does this code of turning the number into binary work?
I’m trying to understand this function that calls itself, but it doesn’t enter into the head as if it can transform a number into binary without at least a repetition, as it works? static int…
-
2
votes3
answers5610
viewsFunction that checks whether a vector is in ascending order
I’m doing an exercise that says: Critique the code of the following function, which promises to decide whether the vector v[0.. n-1] is in ascending order. int verifica (int v[], int n) { //n é o…
-
2
votes2
answers3831
viewsDataframe Pandas - Calculate column based on other
I have a dataframe in the following format: colunas = [ 'COMEDY', 'CRIME', 'Classe Prevista' ] precisao_df = pd.DataFrame(columns=colunas) precisao_df['COMEDY'] = y_pred_proba[:,0]…
-
2
votes1
answer52
viewsHow to describe the execution of the loop for Javascript in Portuguese?
I am a beginner in programming, and I am in the instruction module of the course to which I study and I came across this code below in the double instruction of for. I understood in part how this…
-
2
votes3
answers345
viewsAn array index error
I’m trying to make an algorithm for Selection Sort, just to train algorithms even, in my view my logic is right about ordering, but it is returning me an error that I do not understand. Code: import…
-
2
votes2
answers567
viewsMethod that takes 3 integer values per parameter and returns them ordered in ascending order as an array
I can’t get the array filled returned be printed class Program { static void Main(string[] args) { int valor, valor2, valor3; Maior maior = new Maior(); Console.WriteLine("Digite um numero"); valor…
-
2
votes1
answer243
viewsHelp with ROT-13 C encryption
Some letters of the encryption are passing from 'z', and going to symbols in the ASCII table, why is this occurring? #include <stdio.h> // CRIPTOGRAFIA ROT13 #include <stdlib.h> // A, B,…
-
2
votes2
answers106
viewsMake a game continue or stop as the player chooses
In this game the player chooses a limit number and from this limit will be drawn a number and the user needs to hit it, I’m doing with function, but I do not know how to call again if the user wants…
-
2
votes1
answer720
viewsHelp with simple while summation program
Gentlemen, I started to introduce the programming and the master is requesting an exercise as follows: Write a Python script that asks the user to enter an integer, n, and computes the sum 1 + 2 +…
-
2
votes5
answers2164
viewsSquare root manually in Javascript
I’m trying to manually calculate square root in Javascript. Theoretically it was to stop at 100 according to the value that is in the variable number, but it continues to multiply. Code sample: var…
-
2
votes1
answer311
viewsFraction sum problem in C#
Make a script to calculate and display the sum of the first "N" values of the sequence below. The value "N" will be typed (TextBox), should be positive, greater than zero, but less than fifty. If…
-
2
votes1
answer53
viewsCode ". exe" stopped working
When adding new emails appears the message: project-Email2.exe has stopped working int op = 0, quant = 1; string nomeEmail[quant][2]; while(op != 5){ cout << "Selecione a opção desejada\n[1] -…
-
2
votes2
answers1779
viewsFunction to calculate calories
Create a function called caloriasDeTrote(), which receives per parameter the number of turns represented by a numerical value and returns the amount of calories that will be consumed. For example:…
-
2
votes1
answer140
viewsArray problem in C, where is the error?
I have the following problem to solve: I arrived at this solution: #include <stdio.h> int main() { double numeros[99]; double resultante[49]; int i, j; for (i = 0; i <= 99; i++) {…
-
2
votes2
answers53
viewsShow a missing address
I am doing some algorithms in various languages and in Java I come across a problem, in my function researcher when the value is not found in the list it should return me a None or null, but I can’t…
-
2
votes2
answers378
viewsPrime Numbers with While and For
I don’t understand how a command finds prime values: for i in range(2,30): j = 2 counter = 0 while j < i: if i % j == 0: counter = 1 j = j + 1 else: j = j + 1 if counter == 0: print(str(i) + " é…
-
2
votes2
answers342
viewsValidate an expression based on which parentheses should close
I’m solving a Python exercise where I had to validate an expression based on which the parentheses should close right: Create a program where the user type an expression that uses parentheses. Your…
-
2
votes1
answer249
viewsKotlin - How to wait for the user to return a function called inside the while loop
I have an algorithm that via console helps the user in sorting a list of items, it works well for the console (code below), but I’m adapting the interface to become an app (as print) I wanted that…
-
2
votes2
answers2009
viewsJavascript - How to calculate average data in an array with multiple objects and return in another array
Having an array notasAlunos, as a small example: notasAlunos = [ { matricula: "117", nome: "Joao", materia: "x1", nota: 78 }, { matricula: "117" nome: "Joao", materia: "x8", nota: 80 }, { matricula:…
-
1
votes1
answer216
viewsJava permeability
I’m having some difficulty solving a recursive problem, which I explain below. Given an array of n rows and columns, check for permeability, i.e., having the following matrix (where '*' - represents…
-
1
votes1
answer627
viewsInsert - Jump Lists / Skip Lists
I’m trying to implement the insertion of a node in a jump list, but I’m not making progress with the solution because I don’t know at what point I should add the Node. So far I’ve made this…
-
1
votes1
answer71
viewsRuntime calculation module(%)
Statement of variables: var x= 200; var y= 50; Module: var resposta = x % y; What the module should do, I believe (I calculate): s1 = x / y; s2 = s1 * y; resposta = s2 - x; The question in itself…
algorithmasked 10 years, 4 months ago Rogers Corrêa 2,596 -
1
votes1
answer2722
viewsScroll through a matrix and validate repeated numbers
I am doing a final work in the first semester of the BCC course and I need to do a Mega Sena algorithm with the following features: Maximum of 10 players Each player must bet a minimum of 6 numbers…
-
1
votes1
answer113
viewsHow to fill the data of a tree-shaped element?
I have an element p:tree of Primefaces, and I would like to fill it with existing data in a ArrayList. Actually I’d just like to get an idea about what the algorithm might be that does this.…
-
1
votes1
answer2518
viewsCreate function that returns random numbers in C
I need to create a function that returns random numbers without repetition between 2 intervals. I wanted to create a kind of a card game, where the cards are shuffled, and when they return they…
-
1
votes0
answers59
viewsHow to search by distance
I have a database with coordinates of several locations. I would like to know how, from an informed location, to get only the places you are until a certain distance. I saw a similar question: How…
-
1
votes1
answer100
viewsLogic for Directory System
I have a directory system in the bank ex table directory: id parentDirID Parent dir means q is a subdirectory. What would the function of "copy" directories look like in the system? move directories…