C语言——嵌套循环
答案:1 悬赏:70 手机版
解决时间 2021-03-07 11:41
- 提问者网友:疯孩纸
- 2021-03-07 08:04
C语言——嵌套循环
最佳答案
- 五星知识达人网友:底特律间谍
- 2021-03-07 09:42
#include
int main(int argc, char const *argv[])
{
int n = 0;
while(1)
{
printf("Please enter a number greater than 0 and less than 101
");
scanf("%d",&n);
if (n <= 0 || n > 100)
printf("Error,please try again!
");
else
break;
}
for (int i = 1; i < n/20; ++i)
{
for (int j = 1; j < n/10; ++j)
{
for (int k = 1; k < n/5; ++k)
{
if ( 20 * i + 10 * j + 5 * k == n )
{
printf("$20:%d $10:%d $5:%d
",i,j,k);
}
}
}
}
return 0;
}
int main(int argc, char const *argv[])
{
int n = 0;
while(1)
{
printf("Please enter a number greater than 0 and less than 101
");
scanf("%d",&n);
if (n <= 0 || n > 100)
printf("Error,please try again!
");
else
break;
}
for (int i = 1; i < n/20; ++i)
{
for (int j = 1; j < n/10; ++j)
{
for (int k = 1; k < n/5; ++k)
{
if ( 20 * i + 10 * j + 5 * k == n )
{
printf("$20:%d $10:%d $5:%d
",i,j,k);
}
}
}
}
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯