1.
2。
int main(int argc, const char *argv[])
{
int year,month,day;
int result=0;
printf("请输入:");
scanf("%d/%d/%d",&year,&month,&day);
if(month>12||month<1)
{
printf("error \n");
return 0;
}
switch(month)
{
case 12:
result+=30;
case 11:
result+=31;
case 10:
result+=30;
case 9:
result+=31;
case 8:
result+=31;
case 7:
result+=30;
case 6:
result+=31;
case 5:
result+=30;
case 4:
result+=31;
case 3:
if(year%4==0&&year%100!=0||year%400==0)
{
result+=29;
}else
{
result+=28;
}
case 2:
result+=31;
case 1:
default:
result+=day;
break;
}
printf("%d/%d/%d是当年的第%d天\n",year,month,day,result);
return 0;
}
3.
int main(int argc, const char *argv[])
{
int num1=0,num2=0,result=0;
char punctuation=0;
printf("输入表达式:\n");
scanf("%d%c%d",&num1,&punctuation,&num2);
switch(punctuation)
{
case '+':
result=num1+num2;
break;
case '-':
result=num1-num2;
break;
case '*':
result=num1*num2;
break;
case '/':
result=num1/num2;
break;
case '%':
result=num1%num2;
break;
default:
printf("运算符错误\n");
break;
}
printf("%d\n",result);
return 0;
}
4.
6/7/15
5.
4
6.
int main(int argc, const char *argv[])
{
int num;
printf("请输入一个整数:");
scanf("%d",&num);
switch(num%3)
{
case 0:
printf("3 ");
default:
switch(num%5)
{
case 0:
printf("5 ");
default:
switch(num%7)
{
case 0:
printf("7");
default:
if(num%3!=0&&num%5!=0&&num%7!=0)printf("n");
break;
}
break;
}
break;
}
putchar(10);
return 0;
}
7.
b,c,d:10,12,120
8.c=-75 a=181 d=5 e=6
9.