punteros
Publicado por Dennis (63 intervenciones) el 28/02/2022 22:27:24
Donde esta el error.
El objetivo es crear un puntero donde se almacenen por rango una lista de notas y después mostrarlas por tango las notas.
El objetivo es crear un puntero donde se almacenen por rango una lista de notas y después mostrarlas por tango las notas.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
int leer(int* lista, int rango, int total)
{
int notas;
for(int i = 0; i < total; i++)
{
cout<< "Nota #" << i+1 << ": ";
cin>> notas;
lista[notas/rango]++;
}
return *lista;
}
void mostrar(int* lista, int total){
for(int i = 0; i < total; i++)
{
cout<< "#" << i+1 << "; " << lista[i];
}
}
int main(){
int cantNotas;
int* lista;
int rango;
cout<< "Cantidad de notas: ";
cin>> cantNotas;
cout<< "Rango: ";
cin>> rango;
if(cantNotas % rango == 0)
{
rango += 1;
}
lista =new int[rango];
leer(lista, rango, cantNotas);
mostrar(lista, cantNotas);
}
Valora esta pregunta
0