The basis of the programming cycle-odd sum.

Source: Internet
Author: User

Describe

Computes all odd-numbered and between non-negative integers m to n (including M and N), where m is not greater than N, and N is not greater than 300. For example, M=3, n=12, and the following are: 3+5+7+9+11=35.

Enter two numbers m and N, two numbers separated by a single space, where 0 <= m <= n <= 300. An output line that contains an integer representing all the odd and sample inputs between M and N (including M and N)

7 15

Sample output

55
1#include <iostream>2#include <cstdio>3 using namespacestd;4 intMain ()5 {6     inta,x=0, b,m;7Cin>>a>>m;8     if(a%2==0) a=a+1;//A is not a plural9     if(m%2==0) b=b-1;//b is not a pluralTen      for(inti=a;i<m+1; i+=2) One     { Ax+=i; -     }     -printf"%d", x);  the     return 0; -}

Wrong two times, all because of not careful examining.

The basis of the programming cycle-odd sum.

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.