如何用一个循环编码模式? [英] How do I code pattern with one loop?

查看:57
本文介绍了如何用一个循环编码模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*
**

***

****



I可以使用两个循环轻松编码,但我只想做一个循环?你能帮帮我吗?



我尝试过的事情:



* **
***
****

I can code it easily with two loops but I want to do only one loop? Can you help me?

What I have tried:

#include<stdio.h>
int main() {
	int i,j;
	int n=4;
	
	for(i=1,j=1;i<=n; i++,j++){
		if(j%2==0)
		  printf("\n*");
		else
		  printf("*");
		
	}
}

推荐答案

好吧我们成功了谢谢



alright guys I made it thanks

#include<stdio.h>
int main() {
	int i,j;
	int n=4;
	i=1;
	for(j=0; i<=n; j++) 
	{
		printf("*");
		if(j%i==0) {
			printf("\n");
			i++;
			j=0;
		}
	}
}


这篇关于如何用一个循环编码模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆