嵌入式机考笔试之C语言数组问题
题目要求:有一个整形数组buff[N],buff[N+1]描述buff[N],其中buff[0]=1; buff[1]用来描述buff[0],buff[1]=11,从左往右表示buff[0]中有1个1; buff[2]用来描述buff[1] ,buff[2]=21,从左往右表示buff[1]中有2个1 buff[3]用来描述buff[2] , buff[3]=1211,从左往右表示buff[2]中有1个2,1个1; buff[4]用来描述buff[3] ,buff[4]=111221,从左往右表示buff[3]中有1个1,1个2,2个1; 输入N,0<=N<=25;
输入示例: 复制输入: 1 输出: 11从左往右表示buff[0]中有1个1;
复制输入: 2 输出: 21从左往右表示buff[1]中有2个1
复制输入: 3 输出: 1211从左往右表示buff[3]中有1个2,1个1
复制输入: 4 输出: 111221从左往右表示buff[3]中有1个1,1个2,2个1;
示例代码: 复制#include int main() { int buff[1024]={1};//buff[0]=1 int len=1; int new_buff[1024]={0}; int new_len=0; int cnt=0; int i=0; while(scanf(“%d”,&cnt)!=EOF)//请求输入N { buff[0]=1;//起始值buff[0]=1 len=1; if(cnt==0)//N=0时,输出则为1 { len=1; buff[0]=1; } else { int j,k; int sum=1; new_len=0; for(i=0;i0) { for(j=0;j;j++)>;i++)> 复制![嵌入式机考笔试之C语言数组问题-c语言数组里面套数组 嵌入式机考笔试之C语言数组问题-c语言数组里面套数组](https://file.elecfans.com//web2/M00/63/45/pYYBAGL-NS6AGFTyAAF-GieTVcs203.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBASVRf6Zi_5rC0,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
复制
复制