DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Calendar Loops

09.22.2006
| 3343 views |
  • submit to reddit
        this program is very usefull when you need to know the list of dates of a repetitive task in the week.

I create this program to fill the records of my teaches in a school.

#include <stdio.h>


int meses[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dias[365][3];
/*
0 Lunes
1 Martes
2 Miercoles
3 Jueves
4 Viernes
5 Sabado
6 Domingo
*/

int cursos[7][4]={{0,0,0,0},{2,2,0,0},{1,0,1,1},{0,1,0,0},{0,0,2,2},{0,0,0,0},{0,0,0,0}};

int main(){
    int i,j,k;
    dias[0][0]=5;
    for (i=1;i<365;i++){
        dias[i][0]=(dias[i-1][0]+1)%7;                       
    }    
    k=0;
    for (i=0;i<12;i++){
        for (j=1;j<=meses[i];j++){
            dias[k][1]=i;    
            dias[k][2]=j;
            k++;
        }
    }
    
    for (i=0;i<365;i++){
       // bool salto=false;
        for (j=0;j<4;j++){

            for (k=0;k<cursos[dias[i][0]][j];k++){
                printf("6-%c \t %i - %i \n",'A'+j,dias[i][2]+1,dias[i][1]+1);
//                salto=true;
            }               
        }    
       // if (salto)
       //    printf("\n");
    }
    
    return 0;
}