c语言编程题。注意,是求第1500个数,不是把1500表示成2,3,5的因式表达
展开全部
//来bug了,要工作了,没帮你调试过,思路应该看得懂吧,自己调试一下
void test1()
{
int n = 0;
unsigned int value,temp_val;
int flag = 0;
value = 1;
while(1)
{
temp_val = value;
while(1)
{
if(0 != value%2 && 0 != value%3 && 0 != value%5)
{
flag = 0;
break;
}
if(0 == value%2)
{
value = value/2;
if(1 == value)
{
flag = 1;
break;
}
}
if(0 == value%3)
{
value = value/3;
if(1 == value)
{
flag = 1;
break;
}
}
if(0 == value%5)
{
value = value/5;
if(1 == value)
{
flag = 1;
break;
}
}
}
value++;
if(1 == flag)
{
n++;
printf("%d \n",temp_val);
if(1500 == n)
{
break;
}
}
}
}
void test1()
{
int n = 0;
unsigned int value,temp_val;
int flag = 0;
value = 1;
while(1)
{
temp_val = value;
while(1)
{
if(0 != value%2 && 0 != value%3 && 0 != value%5)
{
flag = 0;
break;
}
if(0 == value%2)
{
value = value/2;
if(1 == value)
{
flag = 1;
break;
}
}
if(0 == value%3)
{
value = value/3;
if(1 == value)
{
flag = 1;
break;
}
}
if(0 == value%5)
{
value = value/5;
if(1 == value)
{
flag = 1;
break;
}
}
}
value++;
if(1 == flag)
{
n++;
printf("%d \n",temp_val);
if(1500 == n)
{
break;
}
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <stdlib.h>
#define I 31
#define J 20
#define K 13
#define L (I * J * K)
int comp(const void *a, const void *b)
{
unsigned long x = *(unsigned long *)a;
unsigned long y = *(unsigned long *)b;
return x > y ? 1 : x < y ? -1 : 0;
}
int main()
{
int i, j, k, l = 0;
unsigned long t[L], a, b, c;
for (i = 0, a = 1; i <= I; i++, a *= 2)
for (j = 0, b = 1; j <= J; j++, b *= 3)
for (k = 0, c = 1; k <= K; k++, c *= 5)
t[l++] = a * b * c;
qsort(t, L, sizeof(unsigned long), comp);
printf("%lu\n", t[1500 - 1]);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用三层循环生成1500个数,排序即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询