交换变量(添加临时变量)
#include<stdio.h>
int main()
{
int m = 5, n = 9, t;
t = m; m = n; n = t;
printf(" m=%d\n n=%d\n", m, n);
return 0;
}
交换变量(不添加临时变量)
#include<stdio.h>
int main()
{
int m = 5, n = 9;
m = m + n;
n = m - n;
m = m - n;
printf(" m=%d\n n=%d\n", m, n);
return 0;
}
判断闰年
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
int year = 0;
scanf("%d", &year);
printf("%d", year);
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
printf("是闰年");
else
printf("不是闰年");
return 0;
}
打印闰年
#include<stdio.h>
int main()
{
int i = 0;
int count = 0;
for (i = 1000; i <= 2000; i++)
if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0))
{
printf("%d ", i);
count++;
}
printf("\ncount=%d\n", count);
return 0;
}