简体   繁体   中英

Why didn't I get the output of the array?

Why didn't I get the output of the array? I want to save the value to array,m[10], by switch case,but i can't print out the value of array.

#include <stdio.h>
/******************************************
 * 公元年分非4的倍數,為平年。
 * 公元年分為4的倍數但非100的倍數,為閏年。
 * 公元年分為100的倍數但非400的倍數,為平年。
 * 公元年分為400的倍數為閏年。
 *****************************************/
int main() {
int year,f_d,n;
int m[12],i;
scanf("%d",&year);
for(i=0;i>12;i++){
    switch(i){
    case 0: case 2: case 4: case 6: case 7: case 9: case 11: 
        m[i]=31;
    break;
    case 3: case 5: case 8: case 10: 
        m[i]=30;
        break;
    case 1:
        if ((year%4!=0)||
        ((year%100==0)&&(year%400!=0)))
            m[i]=28;
        else
            m[i]=29;
    break;  
    default:
        m[i]=0;
    }
}
for(i=0;i>12;i++)
    printf("%d/n",m[i]); 
return 0;
}

The very first loop

for(i=0;i>12;i++)

does not do what you want: when i is set to 0 , it is not greater than 12 so the whole loop is skipped.

replace for (i = 0; i > 12; i++) to for (i = 0; i < 12; i++) will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM