It's quite a long time I did not make a C + + sample program here. Now this time I will attempt to make C + + program to find days in a single month by using the IF statement and the modulus operator. Earlier I mentioned about with this program are listed below:
Produce a program to find the day's (specify day) in May of 2011, based on to start dating ? entered through the user. So for example entered date = 10, then can look your day = Tuesday.
In line with the above questions only then do we may need to look in the calendar and know that the date 1 is Sunday, 2 is Monday, and so on before the 7th would be a Saturday. Then repeat again starting date is Sunday 8 onwards.
If we only use the if statement, only then do we require a fair amount because of possible dates if there are 31 which are inserted from 1 to 31, whereas the possibility that appear only Seven days ie Monday to Sunday.
Check out that day for a date with the date 8, 15, 22, 29. Similarly, for that 2nd day with the date 9, 16, 23, 30. Something similar happened to a different date. If you see the pattern above, for the same day, the modulus 7 of this date can also be exactly the same. That's, on 1, 8, 15, 22, 29 if in same modulus of 7 results: 1. Think about the pair another date is on 9, 16, 23, 30 when the outcome is exactly the same modulus of two.
In conclusion we are able to make use of the modulus operator assistance. The date entered by the user we modulus with 7 after which look into the results. When the modulus equal to 1, then today is Sunday, when the modulus equal to 2 then today is Monday, and so forth. Well to become clearer, please note the C + + program to find the following days:
01 # include <iostream>Produce a program to find the day's (specify day) in May of 2011, based on to start dating ? entered through the user. So for example entered date = 10, then can look your day = Tuesday.
In line with the above questions only then do we may need to look in the calendar and know that the date 1 is Sunday, 2 is Monday, and so on before the 7th would be a Saturday. Then repeat again starting date is Sunday 8 onwards.
If we only use the if statement, only then do we require a fair amount because of possible dates if there are 31 which are inserted from 1 to 31, whereas the possibility that appear only Seven days ie Monday to Sunday.
Check out that day for a date with the date 8, 15, 22, 29. Similarly, for that 2nd day with the date 9, 16, 23, 30. Something similar happened to a different date. If you see the pattern above, for the same day, the modulus 7 of this date can also be exactly the same. That's, on 1, 8, 15, 22, 29 if in same modulus of 7 results: 1. Think about the pair another date is on 9, 16, 23, 30 when the outcome is exactly the same modulus of two.
In conclusion we are able to make use of the modulus operator assistance. The date entered by the user we modulus with 7 after which look into the results. When the modulus equal to 1, then today is Sunday, when the modulus equal to 2 then today is Monday, and so forth. Well to become clearer, please note the C + + program to find the following days:
02 # include <conio>
03
04 void main ()
05 {
06 clrscr ();
07 int date;
08 int remainder;
09 court <<"Program Looking for Day of the Month May 2011" <<endl;
10 court <<endl;
11 court <<"Enter date:";
12 cin>> date;
13
14 if (date <1 | | date> 31)
15 {
16 court <<"Sorry the date that you input invalid";
17}
18 else
19 {
20 court <<"The date" <<date <<"=";
21 remainder = date% 7;
22 if (remainder == 0)
23 {
24 court <<"Saturday";
25}
26 else if (remainder == 1)
27 {
28 court <<"Sunday";
29}
30 else if (rest == 2)
31 {
32 court <<"Monday";
33}
34 else if (remainder == 3)
35 {
36 court <<"Tuesday";
37}
38 else if (remainder == 4)
39 {
40 court <<"Wednesday";
41}
42 else if (remainder == 5)
43 {
44 court <<"Thursday";
45}
46 else if (remainder == 6)
47 {
48 court <<"Friday";
49}
50}
51 getch ();
52}
C + + program above is C + + program to locate or define a unique day in May of 2011. You may make modifications to the other months to meet your requirements. Best of luck.
0 komentar: On Searching for C + + Programs Today In One Month
Posting Komentar