5分 还要详细点....
For
int i;
for(i=0;i<3;i++){
}
定义一个i,每次执行循环以后i增加,直到i不小于3
While
int i;
i=0;
While(i<3){
i++;
}
都是循环。
switch就是判断
例子中判断月份是多少
#include
void main()
{
int year,month,date,leap,days=0;
scanf("%4d%2d%2d",&year,&month,&date);
leap=(year%4==0&&year%100!=0||year%400==0);
switch(month)
{
case 12:days+=30;
case 11:days+=31;
case 10:days+=30;
case 9:days+=31;
case 8:days+=31;
case 7:days+=30;
case 6:days+=31;
case 5:days+=30;
case 4:days+=31;
case 3:days+=28+leap;
case 2:days+=31;
case 1:days+=date;break;
}
printf("%4d年%2d月%2d日是这一年的第%d天。\n",year,month,date,days);
}