example1.c ----------------------------------------------- #include using namespace std; int main(){ int i=0; while(i<5){ cout << i << "\t"; i++; } return 0; } =============================================== example2.c ----------------------------------------------- #include using namespace std; int main(){ int number; cout << "Enter a number: "; cin >> number; while(number > 0){ cout << number << "\t"; number--; } cout << endl; } ================================================ example3.c ------------------------------------------------ #include using namespace std; int main(){ int factor, number; cout << "Enter a number: "; cin >> number; factor = 2; while(number%factor !=0) factor++; cout << "The smallest factor is " << factor << endl; } ================================================ example4.c ------------------------------------------------ #include using namespace std; int main(){ int x, sum=0; cout << "Enter data (-1 to stop) : "; cin >> x; while(x != -1){ sum = sum + x; cout << "Enter data (-1 to stop) : "; cin >> x; } cout << "Sum = " << sum << endl; } ================================================ example5.c ------------------------------------------------ #include using namespace std; int main(){ int n; do{ cout << "Enter a positive value: "; cin >> n; }while(n<0); cout << "The number you entered is " << n << endl; } ================================================ example6.c ------------------------------------------------ #include using namespace std; int main(){ int n; do{ cout << "Enter the mark = "; cin >> n; }while(n<0||n>100); cout << "Mark = " << n << endl; } ================================================ example7.c ------------------------------------------------ #include using namespace std; int main(){ char g, temp; do{ cout << "Enter your gender (f=female/m=male): "; cin >> g; }while(g!='f'&&g!='m'); cout << "Gender = " << g << endl; } ================================================ example8.c ------------------------------------------------ #include using namespace std; int main(){ int x; float reciprocal; do{ cout << "Enter a number: "; cin >> x; if(x<=0) cout << "Error." << endl; }while(x<=0); reciprocal = 1.0/x; cout << "Reciprocal = " << reciprocal << endl; } ================================================