Posts by anonimo • 4,084 points
322 posts
-
-1
votes1
answer23
viewsA: File handling - HELP
From your description what you want is: #include<stdio.h> #include<stdlib.h> #include<locale.h> #include <ctype.h> int main() { setlocale(LC_ALL, "Portuguese"); FILE…
-
-1
votes2
answers63
viewsA: problem with scanf
With the fixes explained in the comment and fixing your string definition (array of characters and not a single character, see if this fits: #include <stdio.h> #include <string.h> /* O…
-
0
votes1
answer18
viewsA: Save specific values from a file
For example input provided: #include <stdio.h> int main(void) { FILE arq; float a, b; arq = fopen("ficheiro.txt", "r"); while (fscanf(arq, "%*s %f %f", &a, &b) != EOF)…
-
0
votes1
answer39
viewsA: How to use the 'while' repeat structure? doubts in a specific exercise
Assuming you want to calculate the total for N products, use: Var produto, totalPedido, precoUnit: real quant, i, N: inteiro Inicio escreva("Informe a quantidade de produtos: ") leia(N) i <- 0…
-
0
votes1
answer27
viewsA: How do I get the spaces just from the last column of the matrix?
Assuming you’re talking about this passage: printf("\nMatriz formada:\n"); for(int i=0; i<linhas; i++){ for(int j=0; j<colunas; j++){ printf("%d ", matriz[i][j]); } printf("\n"); } you can do:…
-
1
votes1
answer37
viewsA: How does the diagonal sum printf of a matrix
See if, by any chance, this is what you wish: #include <stdio.h> int main() { int n=0, total=0; scanf("%d", &n); int matriz[n][n]; printf("tr(A) ="); for(int i=0; i<n; i++) { for(int…
-
1
votes2
answers28
viewsA: Char in function is not recognized in c
See if this is it. I don’t understand ao to conseguindo guardar a letra na variável char. #include <stdio.h> float ers (float, float, float, char); int main () { float x,y,z; char e;…
-
0
votes4
answers142
viewsA: Variable value changes in main function
In the code above x is a global scope variable, this means that at any point in your program you change the value of x it will be changed and the new value recognized throughout the program. When…
-
0
votes1
answer45
viewsA: LOWEST VALUE OF EACH MATRIX ROW
According to the comment would be: #include <stdio.h> #include <stdlib.h> int main() { float notas[10][3] = {0}; //preenchendo matriz for(int aluno = 0; aluno < 10; aluno++) { for(int…
-
0
votes3
answers56
viewsA: Sum of columns
You have reversed the loops in the sum. To sum the columns first vary the columns and internally vary the rows of each column. #include <stdio.h> int main() { int matriz[3][3] = { { 5, -8, 10…
-
0
votes1
answer21
viewsA: Separate string and numbers (Ex.: 00oy285dase556 - num1=00, num2=285, num3=556)
You can start from something like: #include <stdio.h> #include <stdlib.h> #include <ctype.h> int main() { int i=0, j=0, k=0, l, num[10]; char buffer[256], aux[20]; printf ("Informe…
-
1
votes1
answer19
viewsA: How to update the fields of a table based on other records of the same table - Postgre
I think that’s what you want: UPDATE SERTAB a SET a.valor = coalesce((SELECT b.valor FROM SERTAB b WHERE b.tipo = 1 AND b.tipo = a.tipo), 0) WHERE a.filial = 2
-
0
votes1
answer50
viewsA: char returns invalid typed number as option
Here is a possibility based on your code, but there are other alternatives. #include <stdio.h> #include <string.h> int main() { char op[50]; char opc = 's'; char *diaSemana[7] = {"\n1.…
-
0
votes1
answer19
viewsA: Relate Products to duplicated EANS in a relation where 1 product has n EANS. sql language
If you want to identify products that, despite having different codes, have the same EAN try: SELECT ean, GROUP_CONCAT(cod_produto) FROM eans GROUP BY ean HAVING COUNT(cod_produto) > 1 If it is…
-
1
votes2
answers54
viewsA: How do I select some lines of different audiences?
Interpreting "if there is no first line" as no records in this group, try: SELECT * FROM ( (SELECT * FROM tabela WHERE GRUPO = 1 ORDER BY CLIENTE LIMIT 3) a UNION (SELECT * FROM tabela WHERE GRUPO =…
-
1
votes1
answer33
viewsA: UPDATE WITH CASE DOESN’T WORK
You are not using the CASE in a syntactically correct way. Note that in the case of (id_vaga_segunda_opcao = 262) you are returning the result of the expression id_vaga_sistema_vagas_final = 812,…
-
2
votes2
answers74
viewsA: Dúvida Postgresql
I do not know if I understood the desired result but I believe that the use of Common Table Expression can help you. WITH quantidade( Select g.galeria, g.tipo, g.finalidade, count(p.galeria) as…
-
-1
votes2
answers40
viewsA: define the function
Try something like: float soma=0; int pot=1; for(i=1; i<=n; i++) { pot *= 3 * 3; soma += (i*3) * (1/pot); }
-
1
votes1
answer64
viewsA: Crossing a primary key with 2 foreign keys from the same table?
The table LOCATIONS will participate twice in the merge once in the role of origin and again in the role of destination. SELECT * FROM ORDER INNER JOIN LOCATIONS origem ON (ORDER.id_origem =…
-
1
votes1
answer53
viewsA: MYSQL search in fields with equal names
I think what you want is something like: SELECT livros.id_livro, livros.nome, livros.caminho, GROUP_CONCAT(categorias.nome SEPARATOR ';') as categoria FROM livros INNER JOIN categorizados ON…
-
0
votes3
answers79
viewsA: Decrease the code
In function MostraMedia can be: for (i=0; i<18; i++) { soma = 0; for (j=0; j<6; j++) soma += mortes[i*6+j]; media = soma /6; printf ("A media de mortes do ano %d é: %.2f\n", ano[i], media);…
-
0
votes2
answers34
viewsA: Sub-consumption With Different Aggregate Results
I think what you want is: SELECT CODIGO, DESCRICAO, (SELECT SUM(Produtos_Quant.QUANT) AS Expr1 FROM Produtos_Quant WHERE (Produtos_Quant.COD_PRODUTO = C.CODIGO) AND (Produtos_Quant.TIPO <>…
-
0
votes2
answers47
viewsA: sql search filter - exception
Assess if this is what you want: SELECT P.COD_ALUNO, P.NOME, P.ID_TIPO_PESSOAS FROM TB_VOUCHER V INNER JOIN TB_PESSOAS P ON P.COD_ALUNO = V.COD_ALUNO WHERE V.TIPO_VOUCHER = 239 AND V.COD_ALUNO IS…
-
-1
votes1
answer66
viewsA: Query two tables and display the quantity of the group that has the most foreign key records
I believe this query meets your needs: WITH Qtd_Turmas AS ( SELECT id_turma, COUNT(id_aluno) AS qtd FROM Aluno GROUP BY id_turma ), Max_Turmas AS ( SELECT id_turma, MAX(qtd) AS max_qtd FROM…
-
1
votes1
answer26
viewsA: Query return in which field is the value
Use CASE / WHEN: SELECT *, CASE WHEN campo1='valor' THEN 'campo1' WHEN campo2='valor' THEN 'campo2' ELSE 'campo3' END AS campo FROM tb WHERE campo1='valor' or campo2='valor' or campo3='valor'…
-
0
votes2
answers74
viewsA: Mysql - Catch minor record in a 1:N ratio
You will get what you want using the grouping function MIN together with the clause GROUP BY: SELECT `produto`.`titulo`, MIN(`modelo`.`preco`) FROM `produto` INNER JOIN `modelo` ON…
-
0
votes2
answers82
viewsA: Group closer values in Postgresql
With the use of a subselect: SELECT e.data as data_entrada, e.ticket as num_ticket, (SELECT min(s.data) FROM saida s WHERE s.ticket = e.ticket AND s.data > e.data) as data_saida FROM entrada e…
-
2
votes2
answers93
viewsA: How do I get as much and as little as possible of a consult?
You can use CTE: WITH foo(atraso) AS (select DATEDIFF("D",DtVencimento,DtBaixa) as atraso from Entrada where Id='1' and DtEmissao >='01/01/2020' and DtEmissao <='01/12/2020' and ((VlBaixado is…
-
0
votes1
answer25
viewsA: Query with multiple Mysql SELECT’s
Since Mysql does not implement FULL OUTER JOIN simulate with UNION from LEFT JOIN and RIGHT JOIN and using CTE to simplify: WITH cte1 AS (SELECT prefixo FROM getVeiculosLinha AS V JOIN getLinhas AS…
-
-1
votes1
answer55
viewsA: I cannot get my program to calculate the change to 100 in the notes that my client puts. In C
It is almost what you want, adapt to the output in the desired format. #include <stdio.h> int main() { int n, i, j, troco, notas[5]={2, 5, 10, 20, 50}, qtd[5]={0, 0, 0, 0, 0}, soma;…
-
0
votes1
answer30
viewsA: A function that reads only the last integer number written in a text file and returns?
Make sure it’s something like: #include <stdio.h> int main() { FILE * save; char linha[100]; int d; save = fopen ("light.txt" , "r"); if (save == NULL) { printf("Erro ao abrir o arquivo\n");…
-
0
votes1
answer36
viewsA: SQL - doubt in query
Your join syntax is wrong. Try: SELECT p.cpf, p.nome, e.codigo, o.data, o.descricao FROM pessoa p INNER JOIN espectador e ON e.cpfpessoa = p.cpf INNER JOIN Ocorrenciapessoa op ON e.cpfpessoa =…
-
2
votes1
answer107
viewsA: C number of approved students failed
Case what must be executed on condition of a if for more than one command so you need to put the commands in a block {...}. The operator of increment k++; is equivalent to k = k + 1; so don’t do…
-
0
votes1
answer15
viewsA: Help with c++ vectors
Instead of saving the value of the smallest keep the index of the smallest. #include <iostream> using namespace std; int main() { int n,i,menor ; cin >> n; int a[n]; for (int i = 0;…
-
0
votes1
answer49
viewsA: Can someone help me with this exercise?
You have to check the conditions in cascade. You did not set what to do when it occurs tie at all, I considered what appears first in the table. int melhorclassificado(int n, int tab[][6]) { int l,…
-
0
votes1
answer45
views -
1
votes1
answer35
viewsA: Use of Count() for data recurrences
Just use the GROUP BY clause with the COUNT aggregation function. SELECT "metas"."Segmento", "metas"."Perfil", "metas"."Meta", COUNT(*) AS qtd FROM "metas" JOIN "Negócios" ON "Negócios"."Perfil" =…
-
1
votes1
answer59
viewsA: Which country had the largest total population each year
Make a subquery that manages the ratio of the largest populations for each year: SELECT ano, max(cast(coalesce(popM, '0') AS unsigned)+cast(coalesce(popF, '0') AS unsigned)) AS maxpop FROM Populacao…
-
0
votes1
answer18
viewsA: I cannot print the array names received by the scanf, I need to print the 3 after the repetitions of the end
I could not understand what you want with this media_peso, the way it is does not make sense but you did not explain what you want to calculate. To print the name array use a for. When reading the…
-
0
votes1
answer21
viewsA: Show item description only when equal to only appear as " null " or " No Description "
I think something like: SELECT Item, (CASE WHEN EXISTS (SELECT 1 FROM sua_tabela aux WHERE aux.Item = sua_tabela.Item AND aux.Descricao <> sua_tabela.Descricao) THEN NULL ELSE aux.Descricao…
sql-serveranswered anonimo 4,084 -
-1
votes1
answer76
viewsA: Program to list prime numbers less than or equal to the input value
See if this is what you want: #include<stdio.h> int main() { int n, res, i, j; printf("Insira o seu numero aqui: "); scanf("%d", &n); printf("Voce inseriu este numero: %d \n",n); for (i=n;…
-
1
votes1
answer323
viewsA: Describe the averages of each row of a matrix in C
To calculate the mean you have to add the elements of the line and divide by the amount of elements of the line. #include <stdio.h> #include <stdlib.h> int main() { int i, j; float…
-
0
votes1
answer149
views -
0
votes1
answer20
viewsA: How to mount a sub-base with 7 tables?
Build the subselects correctly: SELECT COUNT(cd_cliente) AS qtd_cliente, (SELECT COUNT(cd_funcionario) FROM funcionario) AS qtd_funcionario, (SELECT COUNT(cd_fornecedor) FROM fornecedor) AS…
-
0
votes4
answers265
viewsA: Check if delta is less than zero (Bhaskara’s formula)
I would explain that it has no real roots as there may be imaginary roots: def raizes(a, b, c): D = (b**2 - 4*a*c) if D < 0: print('Não existem raízes reais') else: x1 = (-b + math.sqrt(D)) /…
-
1
votes1
answer170
viewsA: Doubt with Postgresql (Sum & Count)
You must use the GROUP BY clause and the AVG aggregation function. SELECT unidadenegocio.id, AVG(venda.valortotal) FROM unidadenegocio left join venda on venda.unidadenegocioid = unidadenegocio.id…
-
1
votes5
answers312
viewsA: Make a function that calculates the following sum:
Well, your sequence has changed a little by alternating sum and subtraction. Here you have the calculation demonstration: https://www.wolframalpha.com/input/?…
-
0
votes1
answer30
viewsA: Select Chained between two tables using criterion the field of the first
Have you tried using a junction? SELECT codpro, nrentg FROM d12410 JOIN d12400 ON (d12410.nrentg = d12400.nrentg) WHERE d1240.dtentg = '13.10.2020'
-
0
votes2
answers213
viewsA: Generate a list of prime numbers up to 1000. These numbers should form a list, Lprimos. then check in Lprimos whether it is prime or not
Understanding "Generate a list of prime numbers up to 1000" as a list of all prime numbers under 1,000, try: def ehprimo(num,primos): for divi in primos: if num%divi == 0: return False return True…
-
0
votes3
answers1665
viewsA: multiples of 2 and 3 in python
If what you want are the n numbers that are simultaneously multiples of the two numbers try: n = int(input('Quantidade de múltiplos: ')) i = int(input('Primeiro valor ')) j = int(input('Segundo…