#include <stdio.h>
#include <stdlib.h>
int main()
{
int month;
int year;
printf("请用户输入月份,我来判断天数:");
scanf("%d", &month);
switch(month)
{
case 1:
printf("一月份有31天!\n");
break;
case 2:
printf("二月份有28天!\n");
break;
case 3:
printf("三月份有30天!\n");
break;
case 4:
printf("四月份有30天!\n");
break;
case 5:
printf("五月份有31天!\n");
break;
case 6:
printf("六月份有30天!\n");
break;
default:
printf("当前程序只能判断1-6月份!\n");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
printf("请输入n的值:");
scanf("%d", &n);
int i = 1;
int sum = 0;
for(i = 1; i <= n; i++)
{
sum = sum + i;
}
printf("总和:%d\n", sum);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x, y, z;
for(x = 0; x <= 20; x++)
for(y = 0; y <= 100 / 3; y++)
for(z = 0; z <= 100; z++)
{
if(x + y + z == 100 && 15 * x + 9 * y + z == 300)
{
printf("公鸡有%d只,母鸡有%d只,小鸡有%d只\n", x, y, z);
}
}
return 0;
}