[Solved] How to iterate over this series 5 6 7 6 5 6 7 6 5 6 7 6 5… in C? [closed]


#include <stdio.h>

int seq(void){
    static int v = 5, d = 1;
    int ret = v;
    v += d;
    if(v == 5 || v == 7) d = -d;
    return ret;
}

int main(void) {
    for(int i = 0; i < 20; ++i)
        printf("%d ", seq());
    return 0;
}

1

solved How to iterate over this series 5 6 7 6 5 6 7 6 5 6 7 6 5… in C? [closed]