PowerMultiSequence幂积序列

// PowerMultiSequence.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<math.h>

void swap(double& a,double& b)
{
	if(&a==&b)
		return;
	double tmp=a;
	a=b;
	b=tmp;
}

int main(int argc, char* argv[])
{
	
	printf("Input n:\n");
	int n;
	scanf("%d",&n);
	getchar();

	//double xH=log(n)/log(2);
	//double yH=log(n)/log(3);
	int count=0;
	double nums[5000];
	double value;
	/*
	for(int x=0;x<=xH;x++)
		for(int y=0;y<=yH;y++)
			if( (value=pow(2,x)*pow(3,y)) <= n)
			{
				count++;
				nums[count]=value;
			}
			*/
	
	double pow2x=1;
	double pow3y=1;
	for(pow2x=1;pow2x<=n;pow2x*=2)
		for(pow3y=1;pow3y<=n;pow3y*=3)
			if( (value=pow2x*pow3y) <= n)
			{
				count++;
				nums[count]=value;
			}
//下面进行排序
	int lowerIndex;
	for(int j,int i=1;i<count;i++)
	{
		lowerIndex=i;
		for(j=i+1;j<=count;j++)
			if(nums[lowerIndex]>nums[j])
			{
				lowerIndex=j;
			}
		swap(nums[lowerIndex],nums[i]);
	}


	printf("幂序列中小于%d的项数:%d\n",n,count);

	printf("Input m:");
	int m;
	scanf("%d",&m);
	getchar();

	if(m<=count)
		printf("从小到大第:%d项:%.0lf\n",m,nums[m]);
	else
		printf("所输入的m大于序列的项数\n");


	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值