pascal.c 1.27 KiB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cantidad(char *s){
    int max=0;
    for (int i = 0; s[i] ; i++) {
        max=i;
    return max+1;
char* pascal(char *s) {
    //char s1[cantidad(s)];
    int cuociente;
    char *s1=calloc(strlen(s)+1,sizeof(char));
    strcpy(s1,s);
    if (s == NULL){ //caso que sea nulo.
        return NULL;
    cuociente=cantidad(s)/2;
    if(cantidad(s)%2==0){//par
        for (int i = 0; i <cuociente-1 ; i++) {
            if(i%2==0){ // iteracion impar debido a que esta parte siendo iteracion 1,
                s[cuociente-2-i]=s1[cantidad(s)-1-i];
                s[cuociente+1+i]=s1[i];
            if(i%2!=0){// iteracion par
                s[cuociente-2-i]=s1[i];
                s[cuociente+1+i]=s1[cantidad(s)-1-i];
    if(cantidad(s)%2!=0){//impar
        for (int k = 0; k <cuociente-1 ; k++) {
            if (k%2==0){ //iteracion impar
                s[cuociente-2-k]=s1[cantidad(s)-1-k];
                s[cuociente+2+k]=s1[k];
            if (k%2!=0){ //iteracion par
                s[cuociente-2-k]=s1[k];
                s[cuociente+2+k]=s1[cantidad(s)-1-k];
    free(s1);
   // printf("%s",s);
    return s;