1 #include <iostream> 2 #include <fstream> 3 using namespace std; 4 void write(int data,int len) 5 { 6 int numberOfData=data; 7 int pNum[1000]; 8 for (int i=0; i<len ; i++) 9 pNum[i]= numberOfData; 10 11 fstream dataFile; 12 dataFile.open("text.txt",ios::out); 13 if(!dataFile) 14 { 15 cout<<"fail to dataFile"<<endl; 16 exit(0); 17 } 18 for (int i=0;i<len;i++) 19 dataFile<<pNum[i]; 20 dataFile.close(); 21 22 } 23 int main() 24 { 25 int a, b; 26 cout<<"enter two number, please"<<endl; 27 cin>> a >> b ; 28 int max , min; 29 if (a>b) 30 { 31 min=b; 32 max=a; 33 } 34 else 35 if(a<b) 36 { 37 min=a , 38 max =b; 39 } 40 int len=max-min+1; 41 cout<<"the number is "<<endl; 42 for(int v = min ; v<=max ; ++v) 43 { 44 cout<<v<<" "; 45 if((v-min+1)%10==0) 46 cout<<endl; 47 48 49 write(v,len); 50 } 51 return 0 ; 52 }
时间: 2024-10-29 19:07:54