Guest User

Untitled

a guest
May 5th, 2012
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. //Determine the number of positive integers x, where x is
  2. //less than equal to 9,999,999 and the sum of the digits in x is 31.
  3. #include <iostream>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.  
  11. int a=0;
  12. int b=0;
  13. int c=0;
  14. int d=0;
  15. int e=0;
  16. int f=0;
  17. int g=0;
  18. int solution=0;
  19. int percent=0;
  20.  
  21. while ((1000000*a+100000*b+10000*c+1000*d+100*e+10*f+g)<9999999){
  22.     if (a+b+c+d+e+f+g==31){
  23.         solution++;}
  24.     if (g<9){
  25.         g++;}
  26.     else{
  27.         g=0;
  28.     if (f<9)
  29.             f++;
  30.     else{
  31.             f=0;
  32.             if (e<9)
  33.                 e++;
  34.             else{
  35.                 e=0;
  36.                 if (d<9)
  37.                     d++;
  38.                 else{
  39.                     d=0;
  40.                     if (c<9)
  41.                         c++;
  42.                     else{
  43.                         c=0;
  44.                         if (b<9)
  45.                             b++;
  46.                         else{
  47.                             b=0;
  48.                             if (a<9){
  49.                                 a++;}}}}}}}
  50. if((1000000*a+100000*b+10000*c+1000*d+100*e+10*f+g)%99999==0){
  51.     percent++;
  52.     cout << percent <<" Percent" << endl;}
  53. }
  54. cout << solution;
  55. system("PAUSE");
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment