(华为数列--c语言+注释)观察数列,输出其前20项,每4个数一行,每个数占8列。2 ,2, 4, 4, 6, 16, 8…

提示:
奇数项:前一项的2次方
偶数项:2的递增倍数

#include<stdio.h>
#include<math.h>
int main(){
    
    
    int a=2,b=2;
	long long n;//奇数项
	int i=1;//偶数项2的乘数
	int count=0;//便于换行
	do{
    
      
	printf("%20d",b);
	i++;//乘数++
	b=2*i;//偶数项
	count++;
	n=a; //奇数项
	printf("%20lld",n);
	count++;
	a=pow(n,2); //超出一定值将无效
	if(count%4==0) printf("\n");
	}while(count<=20);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_51325053/article/details/112727460