A Experimental topics, design ideas, implementation methods
1. Experimental topics
7-7 calculating the train running time (15 minutes)
Depending on the departure time and time of the train, the program is programmed to calculate the time spent on the journey.
Input Format:
The input gives 2 4-bit positive integers in a row, separated by a space, indicating the train's departure time and arrival time, respectively. The format for each time is 2-bit hours (00-23) and 2-bit minutes (00-59), assuming that the departure and arrival are within the same day.
output Format:
The time in a row to output the journey in the format "hh:mm", where HH is 2-bit hours and mm is 2-bit minutes.
4-6 output Fahrenheit-Celsius temperature conversion table (15 points)
Enter a 2 positive integerlowerAndupper(lower≤ upper ≤100), please output a lower upper Fahrenheit-Celsius temperature conversion table with a value range of [,] and an increase of 2 degrees Fahrenheit each time.
Calculation formula for temperature conversion:C=5X( f ? 32) /9 < Span class= "Mord mathit" > c represents the Celsius temperature, < Span class= "base textstyle uncramped" > f Span style= "Font-family:microsoft Yahei" > indicates Fahrenheit temperature.
Input Format:
Enter 2 integers in a row, each representing lower upper the value of the and, separated by a space.
output Format:
First line output: "Fahr Celsius"
Then each line outputs a Fahrenheit temperature Fahr (integer) with a Celsius temperature of Celsius (occupies 6 character widths, aligns right, retains 1 decimal places).
If the input range is not valid, the output is "Invalid."
4-2-6 is not too fat (10 points)
It is said that a person's standard weight should be his height (in centimeters) minus 100, and then multiplied by 0.9 of the number of kilograms. Real weight and standard weight errors within 10% are perfect bodies (i.e. | Real weight< Span class= "base textstyle uncramped" >? standard weight | < Span class= "base textstyle uncramped" >< standard body weight x10%). The known Jin is twice times the kilogram. Now given the height and actual weight of a group of people, please tell them if they are too fat or too thin.
Input Format:
Enter the first line to give a positive integerN(≤20). ThenNline, each row gives two integers, each of which is a person's heightH( +<H< 200; unit: cm) and real weight w ( << Span style= "Font-family:microsoft Yahei" > W ≤ 300; unit: Jin), separated by a space.
output Format:
Output one line for each person conclusion: if it is perfect body, output; if it is You are wan mei! too fat, output You are tai pang le! ; otherwise output You are tai shou le! .
2. Design ideas:
7-7 calculating the train run time
Because the input is two four-bit integers, the hours and minutes are separated first. The number of hours is directly subtracted from the arrival. If the number of minutes of arrival time is greater than the departure, the number of minutes of arrival is directly subtracted from the departure, if the number of minutes of arrival time is less than the departure, it is necessary to borrow the hour, that is, the number of minutes to arrive plus 60 minus the number of minutes of departure, the number of hours to subtract 1. The problem also takes into account the boundary conditions, which are special cases where the minutes are equal and the number of clocks is equal.
4-6 output Fahrenheit-Celsius temperature conversion table
determine the legitimacy of the data first, if Lower>upper or lower>100, then the direct output invalid. The main is to use a circular statement to increase 2 degrees Fahrenheit and then output the corresponding degree Celsius. Finally, note that the output is formatted correctly.
Is 4-2-6, exactly? It's too fat.
Read the number of n rows, figure out the standard weight, and then use the true weight-the absolute value of the standard body weight to compare with the standard weight, so that it is too fat, too thin or perfect.
3. Implementation method:
7-7 calculating the train run time
Separate the number of clocks and minutes by% and/. Then use the IF statement to determine.
4-6 output Fahrenheit-Celsius temperature conversion table
Use the IF statement and the operator && to determine the legitimacy of the data, and then embed the loop for statement in the IF statement to add 2 degrees Fahrenheit each time.
Is 4-2-6, exactly? It's too fat.
The number of read n rows is reached with a for loop. The absolute value of the real body weight and the standard body weight is calculated using the absolute value function fabs ().
Two SOURCE program
7-7 calculating the train run time
#include <stdio.h>
int main ()
{
int h1,h2,m1,m2;
int t1,t2;
scanf ("%d%d", &t1,&t2);
h1=t1/100;h2=t2/100;
m1=t1%100;m2=t2%100;
if (M1<M2)
{
printf ("%02d:%02d", h2-h1,m2-m1);
}
if (M1>M2)
{
printf ("%02d:%02d", h2-h1-1,m2+60-m1);
}
if (h1==h2 && m1==m2)
{
printf ("00:00");
}
if (m1==m2 && h1!=h2)
{
printf ("%02d:00", H2-H1);
}
return 0;
}
4-6 output Fahrenheit-Celsius temperature conversion table
#include <stdio.h>
int main (void)
{
int lower,upper,f;
Double C;
scanf ("%d%d", &lower,&upper);
if (lower<=upper && upper<=100 &&lower<=100)
{
printf ("Fahr celsius\n");
for (F=lower; f<=upper; f+=2)
{
c=5.0* (F-32)/9.0;
printf ("%d%6.1lf\n", f,c);
}
}
Else
printf ("Invalid.");
return 0;
}
Is 4-2-6, exactly? It's too fat.
#include <stdio.h>
#include <math.h>
int main ()
{
int n,i;
double a,b,c;
scanf ("%d", &n);
For (i=1;i<=n;i++)
{
scanf ("%lf%lf", &a,&b);
c= (a-100) *1.8;
if (fabs (b-c) <c*0.1)
{
printf ("You are WAN mei!\n");
}
if (fabs (b-c) >=c*0.1 && b>c)
{
printf ("You are Tai Pang le!\n");
}
if (fabs (b-c) >=c*0.1 && b<c)
{
printf ("You are Tai Shou le!\n");
}
}
return 0;
}
Three Problems encountered and solutions, experience
These questions are not too difficult, mainly some of the details of the problem, usually pay more attention.
In the 4-6 output Fahrenheit-Celsius temperature conversion table, pay little attention to the output format control (occupy 6 character widths, Align Right, retain 1 decimal places).
The scanf () function often forgets the front & when entering data. Call a mathematical function such as Fabs,sqrt,pow to add a header file #include<math.h>.
to express lower in C language Do not be like math, but separate--lower<=upper&&upper<=100.
The first experiment Report of C language