1、判断一个5位数是不是回文数!
#include <stdio.h>
void main()
{
int num,ge,shi,qian,wan;
printf("请输入一个5位数:");
scanf("%d",&num);
ge = num % 10;
shi = num / 10 % 10;
qian = num / 1000 % 10;
wan = num / 10000;
(ge == wan && shi == qian)?printf("%d是回文数!",num):
printf("%d不是回文数!",num);
printf("\n"); }
2、字符大小写转换
#include <stdio.h>
void main()
{
char ch;
printf("请输入任意一个字符:");
scanf("%c",&ch);
(‘A‘ <= ch && ch <= ‘Z‘)?(printf("%c\n",ch + 32)):(printf("%c\n",ch));
}
3、判断是否是闰年
#include <stdio.h>
void main()
{
int year;
printf("请输入一个4位数的年份:");
scanf("%d",&year);
/* (year % 4 == 0 && year % 100 != 0)?(printf("%d是闰年!",year)):((year % 400 == 0)?(printf("%d是闰年!",year)):(printf("%d不是闰年!",year)));
printf("\n"); */
if(year % 4 == 0 && year % 100 != 0)
{
printf("%d是闰年!",year);
}
else if(year % 400 == 0)
{
printf("%d是闰年!",year);
}
else
{
printf("%d不是闰年!",year);
}
}
程序语言基础 8.14课堂代码