It's not easy to learn at the end of my life. I'm just a beginner and have many problems. I hope you can learn and make progress together!
/*************************************** * ************************************ September 28, 2013 * All rights Reserved, author: Zeng shunyao * Problem description: reads two numbers from the file and calculates the approximate number of the two numbers in the two numbers interval (Textbook Page 9) * algorithm analysis: the exhaustive method. For the given two positive integers, a <= B calculates the approximate number between a and B. * Data Input: read two positive integers from the file, ah, and B. * Data Output: if the maximum number of dikes between a and B is result, div (divisor) is output to the file. * Note: No file operation is performed, this program uses the keyboard to input *********************************** ***************************************/ # include "stdio. h "int SearchDivisor (int a) {int count = 0; for (int I = 1; I <= a; I ++) {if (0 = a % I) {count ++ ;}}return count ;}int main () {int a = 0; // lower bound int B = 0; // upper bound char tag = 'n '; // continue to mark int result = 0; // number of targets int div = 0; // Number of approx. int temp = 0; // temporary storage do {printf ("enter two valid numbers:"); scanf ("% d", & a, & B ); if (a <0 | B <0) {printf ("input error! \ N "); return 0 ;}for (; a <= B; a ++) {temp = searchDivisor (a); if (temp> div) {div = temp; result = a ;}} printf ("Number % d has % d approx! \ N ", result, div); // stdin. flush (); printf ("continue (y/n):"); scanf ("% c", & tag );} while ('y' = tag | 'y' = tag); return 0 ;}
/* Comment */
The younger brother is very afraid of file operations. I hope the master will enlighten me!
This article from the "theory first practice and pay equal attention to" blog, please be sure to keep this source http://69680919.blog.51cto.com/4896756/1303194