# Generating digit numbers of equally total digits : For « Language « C++

Home
C++
 1 Bitset 2 Class 3 Console 4 Data Structure 5 Data Type 6 Deque 7 Development 8 File 9 Function 10 Generic 11 Language 12 List 13 Map Multimap 14 Overload 15 Pointer 16 Qt 17 Queue Stack 18 Set Multiset 19 STL Algorithms Binary search 20 STL Algorithms Heap 21 STL Algorithms Helper 22 STL Algorithms Iterator 23 STL Algorithms Merge 24 STL Algorithms Min Max 25 STL Algorithms Modifying sequence operations 26 STL Algorithms Non modifying sequence operations 27 STL Algorithms Sorting 28 STL Basics 29 String 30 Valarray 31 Vector
 C++ » Language » For Screenshots
Generating digit numbers of equally total digits
 ```         Code submitted by Kean Peng Tan (kptan1980 at gmail.com)         //generate number version I //this program is generating  digit number //numbers of equally total digits //which means digit1+digit2+digit3+digit4 //is equally same shall be generated //read and write a text file #include  #include  #include  using namespace std; main() {   //reading a file     ofstream out("c:\\generate.txt"); // output, normal file       if(!out) {     cout << "Cannot open test file.\n";     return 1;   }     //variables  int input=25; //modified here  int temp[3];  temp[0]=0;  temp[1]=0;  temp[2]=0;  temp[3]=0;  //repetitive loop  int total=0;  int sum=0; // initial sum    int row=0; // initial row   int p1,p2,p3,p4;  p1=temp[0]; //MSB  p2=temp[1];   p3=temp[2];  p4=temp[3];   for(p1=0;p1<10;p1++){     if(p2==10){       p2=0;}  for(p2=0;p2<10;p2++){     if(p3==10){       p3=0;}   for(p3=0;p3<10;p3++){     if(p4==10){       p4=0;}    for(p4=0;p4<10;p4++)    {    //4th digit     //determine loop   sum=p1+p2+p3+p4;              if(sum==input)              {                  out << p1 << p2 << p3 << p4 << " ";                   total++;                  row=total;                  if(row%10==0)                  {                    out << endl;                               }              }   //end sum if                         } //end inner loop p4     }  //end inner loop p3     }  //end inner loop p2   }  //end inner loop p1       out << "The sum of outputs is equal to " << input << endl;   out << "Total: " << total << endl; // display in file   out.close();    cout << "Total: " << total << endl;    cout << "success!" << endl;           system("pause");  return 0; }// end main                    ```
Related examples in the same category
 1 For loop with int value type as the control 2 For statement 3 for loop: A Multiplication Table
 java2s.com  | Contact Us | Privacy Policy Copyright 2009 - 12 Demo Source and Support. All rights reserved. All other trademarks are property of their respective owners.