#include <stdio.h>
#define OCTETOS 4

int main() {
    int ip[OCTETOS] = {172, 20, 5, 88};
    int i;
    int valida = 1;

    for (i = 0; i < OCTETOS; i++) {
        if (ip[i] < 0 || ip[i] > 255) {
            valida = 0;
        }
    }

    if (valida == 1) {
        ip[3] = 0;

        printf("Direccion IP valida\n");
        printf("Direccion de red: ");

        for (i = 0; i < OCTETOS; i++) {
            printf("%d", ip[i]);

            if (i < OCTETOS - 1) {
                printf(".");
            }
        }

        printf("\n");
    } else {
        printf("Error: octeto fuera del rango 0-255\n");
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: