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.