joj1007

1007: Triangles


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K57362163Standard

A triangle can be made up out of dots, like the ones shown below:

The number of dots in each one is called a triangular number. More precisely, a number is said to be triangular if it is of the form ½ n(n+1). The numbers 1, 3, 6, 10, and 15 are all triangular.

Given a number, determine if it is triangular. If it is, draw the corresponding right triangle, if it is not, say so.

Input

A positive integer less than 2000. Each case will be on a separate line. A zero (0) denotes the end of input.

Output

The phrase “<num> is a triangular number.” followed by a right triangle of “*” characters, or the phrase “<num> is not a triangular number.” The triangle should be oriented with the hypotenuse on the right and the right angle in the lower left.

Sample Input

3
4
6
0

Sample Output

3 is a triangular number.
*
**
4 is not a triangular number.
6 is a triangular number.
*
**
***
#include<stdio.h>

int main()

{ void draw(int n);

int i,k,m,n;

while(scanf("%d",&n),n)

{ k=0;

for(i=1;i<=70;i++)

if((i+1)*i/2==n) {k=1;m=i;break;}

if(k)

{printf("%d is a triangular number./n",n);

draw(m);

}

else

printf("%d is not a triangular number./n",n);

}

return 0;

}



void draw(int n)

{int i,j;

for( i=1;i<=n;i++)

{ for( j=1;j<=i;j++)

printf("*");

printf("/n");

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值