想要详细的代码和流程图 最好可以有解释
/*第一题*/
#include <stdio.h>
int main(void)
{
int i, num, index;
int a[9] = {1, 5, 7, 8, 10, 13, 16, 21};
scanf ("%d", &num);
for (i = 0; i < 9; i++)
{
if (num <= a[i])
{
index = i;
break;
}
}
for (i = 7; i >= index; i--)
a[i + 1] = a[i];
a[index] = num;
for (i = 0; i < 9; i++)
printf ("%-3d", a[i]);
return 0;
}
/*第二题*/
#include <stdio.h>
int main(void)
{
int num;
int a = 3, b = 5, c = 7;
printf ("Enter a number: ");
scanf ("%d", &num);
if (num % a == 0 && num % b == 0 && num % c == 0)
printf ("%d可以同时被3 5 7整除\n", num);
else if ((num % a == 0 && num % b == 0) || (num % a == 0 && num % c == 0) || (num % b == 0 && num % c == 0))
{
if (num % a == 0 && num % b == 0)
printf ("%d %d", a, b);
else if (num % a == 0 && num % c == 0)
printf ("%d %d", a, c);
else
printf ("%d %d", b, c);
}
else if ((num % a == 0) || (num % b == 0) || (num % c == 0))
{
if (num % a == 0)
printf ("%d", a);
else if (num % b == 0)
printf ("%d", b);
else
printf ("%d", c);
}
else
printf ("%d不能被3 5 7任何一个数整除\n");
return 0;
}
#include <stdio.h>
int main(void)
{
int i, num, index;
int a[9] = {1, 5, 7, 8, 10, 13, 16, 21};
scanf ("%d", &num);
for (i = 0; i < 9; i++)
{
if (num <= a[i])
{
index = i;
break;
}
}
for (i = 7; i >= index; i--)
a[i + 1] = a[i];
a[index] = num;
for (i = 0; i < 9; i++)
printf ("%-3d", a[i]);
return 0;
}
/*第二题*/
#include <stdio.h>
int main(void)
{
int num;
int a = 3, b = 5, c = 7;
printf ("Enter a number: ");
scanf ("%d", &num);
if (num % a == 0 && num % b == 0 && num % c == 0)
printf ("%d可以同时被3 5 7整除\n", num);
else if ((num % a == 0 && num % b == 0) || (num % a == 0 && num % c == 0) || (num % b == 0 && num % c == 0))
{
if (num % a == 0 && num % b == 0)
printf ("%d %d", a, b);
else if (num % a == 0 && num % c == 0)
printf ("%d %d", a, c);
else
printf ("%d %d", b, c);
}
else if ((num % a == 0) || (num % b == 0) || (num % c == 0))
{
if (num % a == 0)
printf ("%d", a);
else if (num % b == 0)
printf ("%d", b);
else
printf ("%d", c);
}
else
printf ("%d不能被3 5 7任何一个数整除\n");
return 0;
}
温馨提示:答案为网友推荐,仅供参考