Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Determine the number of positive integers x, where x is
- //less than equal to 9,999,999 and the sum of the digits in x is 31.
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int a=0;
- int b=0;
- int c=0;
- int d=0;
- int e=0;
- int f=0;
- int g=0;
- int solution=0;
- int percent=0;
- while ((1000000*a+100000*b+10000*c+1000*d+100*e+10*f+g)<9999999){
- if (a+b+c+d+e+f+g==31){
- solution++;}
- if (g<9){
- g++;}
- else{
- g=0;
- if (f<9)
- f++;
- else{
- f=0;
- if (e<9)
- e++;
- else{
- e=0;
- if (d<9)
- d++;
- else{
- d=0;
- if (c<9)
- c++;
- else{
- c=0;
- if (b<9)
- b++;
- else{
- b=0;
- if (a<9){
- a++;}}}}}}}
- if((1000000*a+100000*b+10000*c+1000*d+100*e+10*f+g)%99999==0){
- percent++;
- cout << percent <<" Percent" << endl;}
- }
- cout << solution;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment