m0_57455732 2021-06-08 13:52 采纳率: 66.7%
浏览 234
已采纳

求数列1,3,3,3,5,5,5,5,5,7,7,7,7,7,7,7的第40项

要用到数组相关的知识

C语言上机作业

急急急

  • 写回答

2条回答 默认 最新

  • CSDN专家-Tk 2021-06-08 14:06
    关注

    代码:

    #include "stdio.h"
    
    int fun(int c)
    {
    	int step = 0;
    	int pf = 1;
    	int nstep = 0;
    	while(step < c)
    	{
    		printf("第%d项,数字是%d \n",step + 1,pf);
    		step++;
    		nstep++;
    		if(pf == nstep)
    		{
    			pf=pf+2;
    			nstep = 0;
    		}
    	}
    	return 0;
    }
    
    void main()
    {
    	int xs = 0;
    	printf("请用户输入项数:\n");
    	scanf("%d",&xs);
    	fun(xs);
    }

    演示效果截图:

    上面便于理解

    下面是根据你题面来做的

    代码:

    #include "stdio.h"
    
    int fun(int c)
    {
    	int step = 0;
    	int pf = 1;
    	int nstep = 0;
    	while(step < c)
    	{
    		printf("%d ",pf);
    		step++;
    		nstep++;
    		if(pf == nstep)
    		{
    			pf=pf+2;
    			nstep = 0;
    		}
    	}
    	return 0;
    }
    void main()
    {
    	int xs = 0;
    	printf("请用户输入项数:\n");
    	scanf("%d",&xs);
    	fun(xs);
    }

    演示效果截图:

     

    如果当前回答解决了你的问题,还请帮忙点一个采纳。

    你的采纳使我们的回答的动力,麻烦了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波