图案使用循环 [英] Pattern Using for loop
本文介绍了图案使用循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用仅循环打印以下模式。
我写了下面的code,给了我,直到数字递增。我怎么能那么递减的另一半。
#包括LT&;&stdio.h中GT;INT主要(无效)
{
INT X,R;
为(R = 1;为r 5; R ++)
{
为(X = 3; X> = R; x--)
{
的printf();
} 为(X = 1; X&下; = R; X ++)
{
的printf(%D,X);
} 的printf(\\ n);
}
返回0;
}
解决方案
增加了一个循环。
为(X = 1; X< =(R-1); X ++)
{
的printf(%D,X);
}
整个code。
#包括LT&;&stdio.h中GT;INT主要(无效)
{
INT X,R;
为(R = 1;为r 5; R ++)
{
为(X = 3; X> = R; x--)
{
的printf();
} 为(X = 1; X&下; = R; X ++)
{
的printf(%D,X);
} 为(X = 1; X&下; =(R-1); X ++)
{
的printf(%D,X);
}
的printf(\\ n);
}
返回0;}
code。在 HTTP运行://$c$cpad.org/oAdx20ai
I have to print the following pattern using for loop only.
I have written the following code which gives me till the the numbers increment. How can I decrement then in the other half.
#include<stdio.h>
int main(void)
{
int x,r;
for(r=1;r<5;r++)
{
for(x=3;x>=r;x--)
{
printf(" ");
}
for(x=1;x<=r;x++)
{
printf("%d",x);
}
printf("\n");
}
return 0;
}
解决方案
Added one more loop
for(x=1;x<=(r-1);x++)
{
printf("%d",x);
}
whole code.
#include<stdio.h>
int main(void)
{
int x,r;
for(r=1;r<5;r++)
{
for(x=3;x>=r;x--)
{
printf(" ");
}
for(x=1;x<=r;x++)
{
printf("%d",x);
}
for(x=1;x<=(r-1);x++)
{
printf("%d",x);
}
printf("\n");
}
return 0;}
code running at http://codepad.org/oAdx20ai
这篇关于图案使用循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文