View Code of Problem 53

#include<stdio.h>
main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=5-i;j++)
		{
			printf(" ");
		}
		for(int k=1;k<=2*i-1;k++)
		{
			printf("*");
		}
		printf("\n");
	}
	for(i=1;i<=n-1;i++)		//此处不用定义i,若果定义了则为重定义
	{
		for(int j=1;j<=i;j++)//此处应定义j
		{
			printf(" ");
		}
		for(int k=1;k<=9-2*i;k++)//此处应定义k
		{
			printf("*");
		}
		printf("\n");
	}
}
/*
Main.c:2:1: warning: return type defaults to 'int'
 main()
 ^
Main.c: In function 'main':
Main.c:18:6: error: 'i' undeclared (first use in this function)
  for(i=1;i<=n-1;i++)  //此处不用定义i,若果定义了则为重定义
      ^
Main.c:18:6: note: each undeclared identifier is reported only once for each function it appears in
*/

Double click to view unformatted code.


Back to problem 53