目录
题目1:获得月份天数
题目2:简单计算器
题目3:翻转直角三角形图案
题目4:带空格的直角三角形
题目5:翻转金字塔图案
题目6:菱形图案
题目7:K形图案
题目8:反斜线图案
题目9:箭形图案
题目10:X形图案
题目11:空心正方形图案
题目12:空心三角形图案
使用数组进行12个月份天数获取
代码实现:
int main()
{
int year = 0;
int month = 0;
int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
while (~(scanf("%d %d", &year, &month)))
{
int day = days[month - 1];
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
if (month == 2)
{
day += 1;
}
}
printf("%d\n", day);
}
return 0;
}
使用switch case语句实现
代码实现:
int main()
{
double n1 = 0.0;
double n2 = 0.0;
char op = 0;
while (~scanf("%lf%c%lf", &n1, &op, &n2))
{
switch (op)
{
case '+':
printf("%.4lf+%.4lf=%.4lf\n", n1, n2, n1 + n2);
break;
case '-':
printf("%.4lf-%.4lf=%.4lf\n", n1, n2, n1 - n2);
break;
case '*':
printf("%.4lf*%.4lf=%.4lf\n", n1, n2, n1 * n2);
break;
case '/':
if (n2 == 0.0)
{
printf("Wrong!Division by zero!\n");
}
else
{
printf("%.4lf/%.4lf=%.4lf\n", n1, n2, n1 / n2);
}
break;
default :
printf("Invalid operation!\n");
break;
}
}
return 0;
}
代码实现:
int main()
{
int n = 0;
while((scanf("%d",&n))!=EOF)
{
int i = 0;
int j = 0;
for(i=0;i
代码实现:
int main()
{
int n = 0;
while((scanf("%d",&n))!=EOF)
{
int i = 0;
int j = 0;
int k = 0;
for(i=1;i<=n;i++)
{
//打印行数
//打印空格
for(j=0;j
代码实现:
int main()
{
int n = 0;
while((scanf("%d",&n))!=EOF)
{
int i = 0;
int j = 0;
for(i=0;i
代码实现:
int main()
{
int n = 0;
while((scanf("%d",&n))!=EOF)
{
int i = 0;
int j = 0;
//上 n
for(i=0;i
代码实现:
int main()
{
int n = 0;
while (~scanf("%d", &n))
{
int i = 0;
int j = 0;
//上
for (i = 0; i < n; i++)
{
//*
for (j = 0; j < n + 1-i; j++)
{
printf("* ");
}
printf("\n");
}
//下
for (i = 0; i < n + 1; i++)
{
for (j = 0; j <= i; j++)
{
printf("* ");
}
printf("\n");
}
}
return 0;
}
代码实现:
int main()
{
int n = 0;
while (~scanf("%d", &n))
{
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
//空格
for (j = 0; j < i; j++)
{
printf(" ");
}
//*
printf("*");
//空格
for (j = 0; j < n - 1; j++)
{
printf(" ");
}
printf("\n");
}
}
return 0;
}
int main()
{
int n = 0;
while (~scanf("%d", &n))
{
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (i == j)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
}
return 0;
}
代码实现:
int main()
{
int n = 0;
while(~scanf("%d",&n))
{
int i = 0;
int j = 0;
//上
for(i=0;i
代码实现:
int main()
{
int n = 0;
while(~scanf("%d",&n))
{
int i = 0;
int j = 0;
for(i=0;i
代码实现:
int main()
{
int n = 0;
while(~scanf("%d",&n))
{
int i = 0;
int j = 0;
for(i=0;i
代码实现:
int main()
{
int n = 0;
while(~scanf("%d",&n))
{
int i = 0;
int j = 0;
for(i=0;j
感谢阅读,欢迎大家批评指正!