Home > Back-end >  To solve, why code inspection without running out what also have no wrong
To solve, why code inspection without running out what also have no wrong

Time:09-29

This is for class on the problem, here is my code, run out what also have no
#include
Int main ()
{
Int year=2008;
Int the month=8;
Int day=8;
Int flag; Int sum; If (year % 4==0 & amp; & Year %==0 100 | 100 year %==0 & amp; & Year % 4!=0)
Flag=1;
The else flag=0;
The switch (month)
{
Case 1: the sum=(31); break;
Case 2: sum=(sum + 28); break;
Case 3: the sum=(sum + 31); break;
Case 4: sum=(sum + 30); break;
Case 5: sum=(sum + 31); break;
Case 6: sum=(sum + 30); break;
Case 7: sum=(sum + 31); break;
Case 8: sum=(sum + 31); break;//use eight days to add here, but with the 31-23 case 9: sum=(sum + 30); break; Case 10: sum=(sum + 31); break;
Case 11: sum=(sum + 30); break;
Case 12: sum=(sum + 31); break; The sum -=23 + flag;//sum -=23 mean by August 31-23 days equals eight days
Printf (" % d % d % d (is the first of the year "% d days, year, month, day, sum);
}
return 0;
}
Because paste effect is not good, there is a picture below, the answer is 221 days

CodePudding user response:

Printf (" % d % d % d (is the first of the year "% d days, year, month, day, sum);
This print to switch to use print outside

CodePudding user response:

reference 1/f, cold wind response: 1023
printf (" % d on % d % d is the first of the year "% d day, year, month, day, sum);
This print to switch to use print outside

Good, good, thank you

CodePudding user response:

reference 1/f, cold wind response: 1023
printf (" % d on % d % d is the first of the year "% d day, year, month, day, sum);
This print to switch to use print outside

I run results also wrong

CodePudding user response:

The result must be wrong, you didn't put in front of a few months the number of days of August together,
Case will only perform a switch, what will you remove the break to see effect

CodePudding user response:

If (year % 4==0 & amp; & Year %==0 100 | 100 year %==0 & amp; & Year % 4!=0) this
Judge condition
If (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400)

CodePudding user response:

When the test variable is equal to the constant in the case, case is followed by the statement will be executed, until meet break statement,
When break statement is encountered, the switch is terminated, the control flow will jump to the next line, after the switch statement
Not every case needs to include break, if the case statement does not contain break, control flow will continue to follow-up case, until meet break,

CodePudding user response:

 # include 

Void fun (int arr [], int len)
{
Arr [0]=2;
Printf (" addr_in_fun: % p \ n ", & amp; Arr);
}
Int main ()
{
Int year=2008;
Int the month=8;
Int day=8;
Int flag;
int sum=0;//-- -- -- -- -- the sum initialization -- -- -- -- -- -- -- -- -- --
If (year % 4==0 & amp; & Year %==0 100 | | 100 year %==0 & amp; & Year % 4!=0)//-- - | to | |
Flag=1;
The else
Flag=0;
for (int i=0; i {
The switch (month)
{
Case 1:
Sum=(31);
break;
Case 2:
Sum=(sum + 28);
break;
Case 3:
Sum=(sum + 31);
break;
Case 4:
Sum=(sum + 30);
break;
Case 5:
Sum=(sum + 31);
break;
Case 6:
Sum=(sum + 30);
break;
Case 7:
Sum=(sum + 31);
break;
Case 8:
Sum=(sum + 31);
break;//use eight days to add here, but with the 31-23 case 9: sum=(sum + 30); break; Case 10: sum=(sum + 31); break;
Case 11:
Sum=(sum + 30);
break;
Case 12:
Sum=(sum + 31);
break;


}
}
//-- -- -- -- -- -- -- -- -- -- - to keep the following two lines of code to the outside of the for loop -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The sum -=23 + flag;//sum -=23 mean by August 31-23 days equals eight days
Printf (" % d % d % d (is the first of the year "% d days, year, month, day, sum);
return 0;
}

VS2015 c + + environment debugging results

CodePudding user response:

Cycle will you use to add, if you don't want to use for you want to use the switch, after the month from backwards, and then remove the break, because the switch case of judging mechanism from bottom to top, know meet meet behind the implementation of the case, but once you start perform case then performed will continue in the future, know break or end of the switch, so you write upside down, put the last can reach the effect of circulation and in January, will first determine a few months, and then from the month is added, remember to remove it break in the flower, do you think of a way to achieve specific logic
  • Related