龙空技术网

C语言 幂集

zhexuewei 218

前言:

此时我们对“c语言算幂”可能比较讲究,看官们都需要分析一些“c语言算幂”的相关文章。那么小编在网摘上网罗了一些有关“c语言算幂””的相关文章,希望大家能喜欢,姐妹们一起来学习一下吧!

#include <stdio.h>#include <string.h>#include <math.h>int main(void){	//list all binary numbers of length n	int n=6;	char *ch[]={"1","2","3","4","5","6"};	char* strTemp="";	char* str="";	int count=0;	//index	int i=0;	int j=0;	for(i=0; i<(int)pow(2,n); i++)	{		for(j=n-1; j>=0; j--)		{			//type cast			//float to int			if(i & (int)pow(2,j))			{				//printf("1");				//duplicate ch[j] to strTemp				//then operations based on strTemp				strTemp=strdup(ch[j]);				//insert strTemp befor str				//so they will have right order				sprintf(strTemp, "%s%s", strTemp, str);				//copy strTemp back to str				//str is result needed				str=strdup(strTemp);			}			else			{				//printf("0");			}		}		count++;		printf("%s\n", str);		str[0]=0;	}	printf("\n\n");	printf("count=%d\n", count);	return 0;}

标签: #c语言算幂