//2023.2.3渔火 Linux迷 www.linuxmi.com
int main()
{
int month;
printf("输入月份:");
scanf("%d",&month);
switch((month-1)/3)
{
case :
printf("%d月是第1季度\n",month);
break;
case 1:
printf("%d月是第2季度\n",month);
break;
case 2:
printf("%d月是第3季度\n",month);
break;
case 3:
printf("%d月是第4季度\n",month);
break;
default:
printf("输入错误\n");
break;
}
//2023.2.3渔火 Linux迷 www.linuxmi.com
return ;
}
(month-1)/3
”。当输入月份1、2、3时,表达值为0,以此类推。
//2023.2.3渔火 Linux迷 www.linuxmi.com
int main()
{
int year,month,days;
printf("请输入年,月:");
scanf("%d,%d",&year,&month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
break;
case 4:
case 6:
case 9:
case 11:
days=30;
break;
case 2:
if(year%400==||year%4==&&year%100!=)
days=29;
else
days=28;
break;
}
printf("%d年%d月的天数是%d天\n",year,month,days);
//2023.2.3渔火 Linux迷 www.linuxmi.com
return ;
}
#include<stdio.h>
/2023.2.3渔火 Linux迷 www.linuxmi.com
int main()
{
int year,k;
printf("输入年份:");
scanf("%d",&year);
if((year%4==&&year%100!=)||(year%400==))
k=1;
else
k=;
if(k)
printf("%d是闰年\n",year);
else
printf("%d不是闰年\n",year);
//2023.2.3渔火 Linux迷 www.linuxmi.com
return ;
}
//2023.2.3渔火 Linux迷 www.linuxmi.com
int main()
{
int n,x,y,z;
scanf("%d",&n);
if(n<100||n>999)
printf("输入错误!\n");
else
{
x=n/100;
y=n/10%10;
z=n%10;
if(x<y&&y<z)
printf("%d是升序数\n",n);
else
printf("%d不是升序数\n",n);
}
//2023.2.3渔火 Linux迷 www.linuxmi.com
return ;
}
//2023.2.3渔火 Linux迷 www.linuxmi.com
int main()
{
int x;
printf("请输入一个整数:");
scanf("%d",&x);
if(x%2!=)
printf("%d是奇数\n",x);
else
printf("%d是偶数\n",x);
//2023.2.3渔火 Linux迷 www.linuxmi.com
return ;
}
相关链接:
https://www.linuxmi.com/learn-c-language-from-scratch-1.html
https://www.linuxmi.com/learn-c-language-from-scratch-2.html
https://www.linuxmi.com/learn-c-language-from-scratch-3.html
https://www.linuxmi.com/learn-c-language-from-scratch-4.html
-
https://www.linuxmi.com/learn-c-language-from-scratch-5.html