[AYUDA] Programacion en C


V3n0m

ssj
Noder
Buenas gente, necesito a alguien que me pueda ayudar con este ejercicio, estuve investigando pero no encontre mucho al respecto y me quede trabado ahi xd, si alguien me puede iluminar mejor, de todas formas voy a seguir buscando e intentando

Ejercicio:
Escribir un programa que mediante la utilización de un bucle for muestre por pantalla lo siguiente:
*
**
***
****
*****
 

V3n0m

ssj
Noder
Habia una equivalencia de numeros con los caracteres, creo que tengo que usar esa lista pero no se el nombre
 

Thegjv

Moder fav <3
Noderador
Nodero
Noder
Buenas,

Te doy una primera pista, esta es la tabla que tienes que usar con los valores ascii

1655236752585.png



Aunque también podrías usar el propio carácter "*"

Si necesitas más ayuda dimelo y te echo un cable ;)
 
  • Fueguito
Reacciones : V3n0m

Rodkaiser

Més que un nodero
Noderador
Nodero
Noder
prefiero NodoCoños jajajajajajajaj
toma aqui lo tienes

C:
void dibuja_piramide(int n){
    for(int j = 0; j<n; j++){
            for(int i = 0; i<j+1; i++){
            printf("*");  
        }
        printf("\n");
    }
}
Te me has adelantado. También te digo que ya hay que ser terrorista para utilizar como primer índice la j
 
  • Hahaha
Reacciones : Ivanof y V3n0m

rabilongo

Miembro
prefiero NodoCoños jajajajajajajaj
toma aqui lo tienes

C:
void dibuja_piramide(int n){
    for(int j = 0; j<n; j++){
            for(int i = 0; i<j+1; i++){
            printf("*");
        }
        printf("\n");
    }
}
dos "for" y texto sin formato en printf, ineficiente

C:
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    char *str; // declare only once, outside the for :)
    for (int i = 0;i < 5; ++i) {
        str = (char *)malloc((i + 2) * sizeof(char)); // reserve memory for the string (i + 1 = number of "*')
        str = (char *)memset(str, '*', i + 1); // set i+1 bytes of "str" to '*'
        write(1, str, i + 1); // print all '*' (write systemcall is better than printf function, because is a systemcall)
        write(1, "\n", 1); // print the new line
        free(str); // allways renember to free the memory :D
    }
    return (0);
}

Nota: esto es por hacer la coña, no son conceptos que un novato deberia entender, el ejemplo de RubRub es bastante mas util :)
 
Última edición:
  • Fueguito
  • Hahaha
Reacciones : Ivanof y V3n0m