Xiao Ming is very interested in numbers containing 2, 0, 1, and 9 in the digits (excluding leading 0). Such numbers from 1 to 40 include 1, 2, 9, 10 to 32, 39, and 40, a total of 28 , their sum is 574.
What is the sum of all such numbers from 1 to n?
Input format
The input line contains an integer n.
Output format
Output a line containing an integer representing the sum of the numbers that satisfy the condition.
Input and output samples
Input: 40
#include<stdio.h>
int main()
{
int n = 0, sum = 0, number = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
sum = i;
while (sum != 0)
{
if (sum % 10 == 2 || sum % 10 == 0 || sum % 10 == 1 || sum % 10 == 9)
{
number += i;
break;
}
sum /= 10;
}
}
printf("%d", number);
return 0;
}
There are very few C language solutions for the Lanqiao Cup on the Internet, and it is difficult to get academic reference. The freshman blogger has limited abilities and can only provide some solutions to question C from the entry to popularization stage.