Note: This essay is directly referenced in the "C++primer (fourth Edition) Exercise solution (full version)". Here is mainly for the convenience of my repeated reading later.
Exercise 1.19
What results will the program produce if the number 1000 and 2000 are given in the title? Modify the program so that each line outputs no more than 10 digits.
Troubleshooting
1 intMain ()2 {3 intv1, v2, low,up;4cout <<"Enter Tow Numbers"<<Endl;5Cin >> v1 >>v2;6 if(V1 <v2)7 {8Low =v1;9up =v2;Ten } One Else A { -Low =v2; -up =v1; the } -cout <<"Values of"<< Low <<" to"<< up <<"inclusive is:"<<Endl; - for(intval = Low,count =1; Val <= up; ++val,++count) - { +cout << Val <<" "; - if(count%Ten==0) + { Acout <<Endl; at } - } -cout <<Endl; - return 0; -}
The number of outputs is recorded with the variable count, and a newline character is output if the value of Count is an integer multiple of 10.
C + + Primer fourth Edition after-school practice solution Exercise 1.19