Maximum number of questions

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.