1.在屏幕上输出以下图案:

#define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <stdlib.h>
int main()
{
	int i , j, n ;               /* i为行数,j 为星号数(列数),n为所需要的行数*/
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= 2 * i - 1; j++)
			putchar('*');
			putchar('\n');
	}
	for (i = 1; i <= n - 1; i++)
	{
		for (j = 1; j <= 2 * (n - i) - 1; j++)
			putchar('*');
		putchar('\n');
	}
	system("pause");
	return 0;
}

2.求出0~999之间的所有“水仙花数”并输出。
“水仙花数”是指一个三位数,其各位数字的立方和确好等于该数本身,如;153=1+5+3?,则153是一个“水仙花数”。

# include <stdio.h>
# include <stdlib.h>
int main()
{
	int a, b, c, t;
	{
		for ( a = 1; a <= 9; a++){
			for ( b = 0; b <= 9; b++){
				for ( c = 0; c <= 9; c++){
					if ((a * 100 + b * 10 + c * 1) == (a*a*a + b*b*b + c*c*c))
					{
						t = a*a*a + b*b*b + c*c*c;
						printf("水仙花数是:%d\n", t);
					}
				}
			}
		}
	}
	system("pause");
	return 0;
}

3.求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和,其中a是一个数字,
例如:2+22+222+2222+22222

#define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <stdlib.h>
int main()
{
	int a, b, c, d, e, i, sum;
	printf("请输入一个整数:");
	scanf("%d", &i);
	a = i;
	b = i * 10 + a;
	c = i * 100 + a + b;
	d = i * 1000 + a + b + c;
	e = i * 10000 + a + b + c + d;
	sum = (a + b + c + d + e);
	printf("%d\n", sum);
	system("pause");
	return 0;
}

4.猜数字小游戏:

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void menu()
{
	printf("********************\n");
	printf("**   1.开始游戏   **\n");
	printf("**   0.退出游戏   **\n");
	printf("********************\n");
}

void game()
{
	int random_num = rand() % 100 + 1;
	int input = 0;
	while (1)
	{
		printf("请输入您要猜的数字:");
		scanf("%d", &input);
		if (input>random_num)
		{
			printf("猜大了!\n");
		}
		else if (input<random_num)
		{
			printf("猜小了!\n");
		}
		else
		{
			printf("猜对了!\n");
			break;
		}
	}
}
int main()
{
	int input = 0;
	srand((unsigned)time(NULL));
	do
	{
		menu();
		printf("请选择:");
		scanf("%d", &input);
		if (input==1)
		{
			game();
			break;
		}
		else if (input==0)
		{
			break;
		}
		else
		{
			printf("您的输入有误,请重新输入!\n");
			break;
		}
	} 
		
		while (input);
	system("pause");
		return 0;
}