Skip to content

Largo máximo de ID #39

Closed Answered by CataAlamos
JavierMoralesD asked this question in Tarea 0
Discussion options

You must be logged in to vote

Hola, un ID es idealmente un int. Te dejo un ejemplo de cómo imprimirlo y aumentar el ID tanto en int como string.

#include <stdio.h>
#include <string.h>

int main() {
    int id = 0;
    int number_of_penguins = 10;

    for(int i = 0; i < number_of_penguins; i++) {
        printf("Penguin %d says hello\n", id);
        id++;
    }

    // Ahora con un ID como string
    char id_str[10];
    id = 0;  // Reiniciamos id

    for(int i = 0; i < number_of_penguins; i++) {
        sprintf(id_str, "%d", id);
        printf("Penguin ID %s says hello\n", id_str);
        id++;
    }

    return 0;
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JavierMoralesD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants