first, the experiment topic, the design idea, realizes the method
Experiment Topic 1: The third experiment calculates the piecewise function
(7-7 calculate train run time)
Design ideas: By the test instructions know, need to input two time processing, then the minute subtract, the hour subtracts, if arrives the minute is smaller than the departure minute, needs to arrive at the minute to do "borrow" processing.
Implementation method: If the minute of arrival is greater than or equal to the time of departure, then the hours and minutes are directly subtracted, the train running time is drawn, if the minute arrived is less than the time of departure, then the arrival of the minutes plus 60后 and departure minutes to subtract, so that the arrival of the hour minus 1 after the departure hour subtraction, Draw the train's running time.
Experiment Topic 2: The fourth time to calculate the piecewise function and the loop new (4-3 to find one of the first n of the sequence N and)
Design idea: Use the loop of the for statement so that each result is added to S.
Implementation method: Set A, S, make a=1, and when A<=n there is a plus a cycle, while calculating each a corresponds to the value of 1.0/a, so that the s=s+1.0/a, so that S equals n one of the sequence of the first N and.
Experiment Topic 3: SectionFour Branch + loop boost (three digits in 4-2-5 reverse order)
Design ideas: Calculate the input three-bit positive integer hundred, 10 bits, and then the bit by 100, 10 bits multiplied by ten, hundreds multiplied by one, add to get reverse three digits.
Implementation method: The original three digits divided by 100 to get the hundred number A, the original three digits minus a by 100 divided by 10 to get 10 digits B, the original three digits minus a by 100 minus the B by 10 to get single digit C, and then C by 100 plus B by 10 plus a to get reverse three digits.
second, the source program
Experiment Topic 1:
The third experiment calculates the piecewise function
(
7-7 Calculating the train run time
)
int a,b,c,d,e,f,hh,mm;
scanf ("%d%d", &a,&b);
D=A%100;/*01 points */
C= (a-d)/100;/*12*/
F=b%100;/*30 points */
E= (b-f)/100;/*15*/
if (d<=f) {
Hh=e-c;
mm=f-d;
}
else{
Hh=e-1-c;
mm=f+60-d;
}
printf ("%02d:%02d", hh,mm);
Experiment Topic 2:
The fourth time to calculate the piecewise function and the loop new (4-3 to find one of the first n of the sequence N and)
int a,n;
Double S;
scanf ("%d", &n);
s=0.00;
for (a=1; a<=n; a++) {
s=s+1.0/a;
}
printf ("sum =%.6f", S);
Experiment Topic 3: SectionFour Branch + loop boost (three digits in 4-2-5 reverse order)
int a,b,c,a,b;
scanf ("%d", &a);
c=a%10;
b= (A%100-C)/10;
A= (a-c-10*b)/100;
B=c*100+b*10+a;
printf ("%d", B);
three. Problems encountered and solutions, experience
Encounter the problem of large amount of information to clean up the problem, extract useful messages, flexible use of various statements to solve problems. In particular, it is important to note that some differences, such as assignment "=" and "= =", can only be compared in the case of parentheses in the IF statement. After a long period of practice and the guidance of the teacher, my C language will be more and more powerful!
The first experiment Report of C language