C Language Experiment Report

Source: Internet
Author: User

A The experiment topic, the design idea, realizes the method.

The third experiment 7-7 calculates the train run time,

The fourth time to calculate the piecewise function and the loop new 4-6 output Fahrenheit-Celsius temperature conversion table,

Fourth Branch + loop-enhanced version 4.2.7 sleep.

Design ideas: The key to the calculation of the train operation is the operation method, the unified transformation of the measurement, and then the operation.

4-6 output Fahrenheit-Celsius temperature conversion table and 4.2.7 the number of indefinite integer-bound processing data is entered, and a for loop is required for each volume in the program to operate sequentially and to take advantage of the IF-scoped range.

Implementation method:

1. For the 7-7 calculation of the train running time, the key is the operation method, the problem will be converted into minutes and then the time of the operation, and in the output using%02d, so that the results in less than two digits of the previous bit 0.

2. For 4-6 output Fahrenheit-Celsius temperature conversion table, according to the requirements of input two indefinite integer, through the conditions to determine the scope, and then through the for loop run, and finally output as required. (Note that a Celsius temperature Celsius occupies 6 character widths, aligns right, and retains 1 decimal places.) )

3. For 4.2.7 to sleep, enter an indefinite integer as required, and the integer determines the amount of data to be processed next, in order to facilitate our batch of output, the concept of an array is introduced. The last batch output is judged by embedding the IF statement in the For loop.

Two SOURCE program

The third experiment 7-7 calculates the train running time:

#include <stdio.h>
int main ()
{
int x, y;
int hour, minute;
scanf ("%d%d", &x,&y);
x=x/100*60+x%100;
y=y/100*60+y%100;
Hour= (y-x)/60;
Minute= (y-x)%60;
printf ("%02d:%02d", Hour,minute);


return 0;
}

Fourth time calculation of piecewise functions and loops new 4-6 output Fahrenheit-Celsius temperature conversion table

#include <stdio.h>
int main ()
{
int Fahr, lower, upper;
double Celsius;
scanf ("%d%d", &lower,&upper);
if (lower<=upper&&upper<=100) {
printf ("Fahr celsius\n");
for (fahr=lower; fahr<=upper; fahr+=2) {
Celsius = 5.0 * (FAHR-32)/9.0;
printf ("%d%6.1lf\n", Fahr, Celsius);
}
}else{
printf ("Invalid.");
}
return 0;
}

Fourth Branch + loop-enhanced version 4.2.7 sleep.

#include <stdio.h>
Char name[9];
int main ()
{
int n,r,t,i;
scanf ("%d\n", &n);
for (i=1;i<=n;i++)
{
scanf ("%s%d%d\n", name,&r,&t);
if (r<15| | r>20| | t<50| | T>70)
{
printf ("%s\n", name);
}
}
return 0;
}

Three Problems encountered and solutions, experience

1. The specific output format (%02d,%6.1lf,%s) for many outputs is not understood, and is eventually resolved by means of a book lookup.

2. Ignore the output is the character of the consideration, still use int cause error, after the communication with the classmate, to be resolved.

3. The use of relational operators is not skilled, (example lower<=upper&&upper<=100) to their connection symbols do not know, after the help of Baidu and teaching assistants to master.

4. Array char[], after the classmate learned that the number in parentheses, the number of data stored in the array.

All in all, these experiments have made me understand that writing procedures requires careful examination, every small mistake can cause a big problem, and think of the problem not for granted, a lot of problems are here.

C Language Experiment Report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.