用函数输出1000以内所有水仙花数;求a+aa+aaa+aaaa+……的和

#include<stdio.h>
#include<math.h>
int SumS(int n,int m)//求a+aa+aaa……的和
{
	int tmp = m;
	int result=m;
	for (int i = 1; i <= n-1; i++)
	{
		m = tmp + m * 10;
		result += m;
	}
	return result;
}
int Narc(int n)
{
	int n1;
	int n2;
	int n3;
	int sum;
	for (int n = 100; n < 1000; n++)
	{
		n1 = n / 100;
		n2 = n / 10 - 10 * (n / 100);
		n3 = n % 10;
		sum = n1 * n1 * n1 + n2 * n2 * n2 + n3 * n3 * n3;
		if (sum == n)
		{
			printf("%d\n", sum);
		}
	}
	return 0;
}
int main()//主函数内把两个函数分开做成了注释,需要用哪个函数时,对相应的主函数内代码进行释放
{
	//a+aa+aaa+……
	/*int n;
	int m;
	printf("请输入位数及数值\n");
	scanf_s("%d%d", &n,&m);
	int result = SumS(n, m);
	printf("%d\n",result);*/
	//水仙花数
	/*int sum =0;
	int n=100;
	Narc(n);
	return 0;*/
}

上一篇:微信小程序生成二维码


下一篇:华为路由器本地AAA认证