Find the sum of the first 5 items of SN=A+AA+AAA+AAAA+AAAAA, where a is a number
such as 2+22+222+2222+22222
#include <stdio.h>
int main ()
{
int num=0;
int n=0;
int sum=0;
int tmp=0;
scanf ("%d", &num);
scanf ("%d", &n);
Tmp=num;
while (n)
{
sum+=tmp;
Tmp=tmp*10+num;
n--;
}
printf ("%d\n", sum);
System ("pause");
return 0;
}
The results of the program run are as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/74/C6/wKiom1Yon5jgbtuRAACuksyEFCA693.jpg "title=" The sum of the first 5 items. png "alt=" wkiom1yon5jgbturaacuksyefca693.jpg "/>
9 times between 1~100. #include <stdio.h>int main () {int i=0;int count=0;for (i=1;i<100;i++) {if (i%10==9) count++; if (i/10==9) count++;} printf ("%d\n", count); System ("pause"); return 0;}
The result of the program operation is:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/C5/wKiom1Yon3azkZGlAADIplTkNZk266.jpg "title=" 9 times. png "alt=" wkiom1yon3azkzglaadipltknzk266.jpg "/>
Calculating simple mathematical formulas in C language