- 分别获得一个四位数的个、十、百、千位上的数字
cpp
#include <stdio.h>
int main(void)
{
int num = 1234;
int ge = 0;
int shi = 0;
int bai = 0;
int qian = 0;
ge = num % 10;
shi = num / 10 % 10;
bai = num / 100 % 10;
qian = num / 1000;
printf("ge = %d\n", ge);
printf("shi = %d\n", shi);
printf("bai = %d\n", bai);
printf("qian = %d\n", qian);
return 0;
}
- 判断闰年
cpp
#include <stdio.h>
int main(void)
{
int year = 0;
scanf("%d", &year);
if (0 == year % 4 && 0 != year % 100 || 0 == year % 400)
{
printf("leapyear!\n");
}else
{
printf("not leapyear!\n");
}
return 0;
}
- 打印水仙花数
cpp
#include <stdio.h>
int main(void)
{
int num = 0;
int ge = 0;
int shi = 0;
int bai = 0;
for (num = 100; num < 1000; num++)
{
ge = num % 10;
shi = num / 10 % 10;
bai = num / 100;
if (ge * ge * ge + shi * shi * shi + bai * bai * bai == num)
{
printf("%d\n", num);
}
}
return 0;
}