Comprehensive Thinking !~

Source: Internet
Author: User
Sum of squares and cubes and

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/others) total submission (s): 90266 accepted submission (s): 28902

Problem description gives a continuous integer and calculates the sum of squares of all even numbers and the sum of all odd numbers. The input data contains multiple groups of test instances. Each group of test instances contains a row consisting of two integers, M and N. Output for each group of input data, the output line should contain two integers x and y, indicating the sum of the squares of all the even numbers in the continuous integer of the segment and the sum of all the odd numbers of cubes and. You can think that a 32-bit integer is enough to save the result. Sample input1 3 2 5 sample output4 28 20 152 authorlcy source C language programming exercises (I) recommendjgshining | we have carefully selected several similar problems for you: 2008 2009 2012 2014 2017 is such a simple question. I didn't expect any errors, but I always chose to ignore them. First try, second try: Wrong answer -- the range of M and N in the question !! Consider m> N!
#include<stdio.h>int main(){    int m=0, n=0, i=0, resulto=0, resulte=0;    while(scanf("%d%d", &m, &n)!=EOF){        for(i=m; i<=n; i++){            if(i%2){                resulto= resulto+i*i*i;            }            else{                resulte=resulte+i*i;            }        }        printf("%d %d\n", resulte, resulto);        resulte=resulto=0;    }    return 0;}


Third try: accepted

#include<stdio.h>int main(){    int m=0, n=0, i=0, resulto=0, resulte=0, temp=0;    while(scanf("%d%d", &m, &n)!=EOF){        if(m>n){            temp=m;            m=n;            n=temp;        }        for(i=m; i<=n; i++){            if(i%2){                resulto= resulto+i*i*i;            }            else{                resulte=resulte+i*i;            }        }        printf("%d %d\n", resulte, resulto);        resulte=resulto=0;    }    return 0;}

It's about to become Junior. But it still does what other people do in their freshman year.

Be careful. Multiple exercises. Come on.

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.