Calculation Sn = 2 + 22 + 222 + 2222 + 22222

Calculation Sn = 2 + 22 + 222 + 2222 + 22222

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i = 0;
	int n = 0;
	int j = 0;
	int temp = 0;
	int sum = 0;
	scanf("%d", &i);
	scanf("%d", &n);

	for (j = 0; j < n; j++)
	{
		temp = temp * 10 + i;
		sum += temp;
	}
	printf("sum=%d", sum);
  system("pause");
	return 0;
}

Here Insert Picture Description
key point
Each number is ten times before adding a i

This program can not only be considered as a dynamic title is written, did not write the dead.

Published 22 original articles · won praise 5 · Views 3206

Guess you like

Origin blog.csdn.net/weixin_45271990/article/details/104319520