I want to learn C # Language Programming [solution] (1): input the number of minutes, which are output in the form of hour, minute, and second.

Source: Internet
Author: User

Question

 

Input minutes, in the form of hour, minute, and second

 

Question objective

 

The objective is to enable beginners to master the knowledge points and related skills required to answer this question. Then, by analyzing the problem-solving ideas step by step, they can write the questions by themselves.Code.

 

Question Analysis

 

This topic is designed to allow users to enter a positive integer in minutes, and then calculate and output the corresponding results based on the Conversion Relationship Between hours and minutes: 1 hour = 60 minutes.

 

Skill Requirements

 

Variables, data types, operators, input and output

 

Skill Review

 

Variable: a variable is a piece of memory space named after it is killed.ProgramThe amount of changes that can occur during running. A variable can be regarded as a container. The data stored in the container is determined by the data type that defines the variable.

Data Type: the data type is a set of values and a group of operations defined on the value set.

Operator: The operator is used to execute code operations. operations are performed on more than one operand project.

Input and Output: the console class is used for console input.

 

Solutions

 

We already know the skills and related knowledge points required to answer this question. How can these knowledge points be applied to reality? This requires a detailed analysis of the question.

Let's enter a positive integer in minutes and convert it to the corresponding hours and minutes, for example, 110 minutes = 1 hour and 50 minutes.

Now let's take the last 110 minutes as an example: first, let's take a look at how much is the 110 minute to the hour? The answer is 1. Why? Not decimal?

This is because of the relationship between data types in C #. In the integer type, if the calculation results between integers are stored as integers, for example, int A = 3/2;

The result is directly converted to the integer type. Note that the decimal point is not rounded down, but the decimal point is removed. The final value of A is 1 rather than 1.5;

This is the "/" operator in the operator, and we know that the time-and-hour conversion is 60, so 110/60 = 1. Now we have obtained the hour, how can we get the remaining minutes?

This requires the modulo operator "%" in C # To perform operations. The modulo operator is also called the remainder operation. It is used to retrieve the remainder that cannot be divisible in a division operation. For example, if int A = 5% 2; 5 cannot be rounded out by 2, and the remainder is 1, the value of a is 1. At this point, our business and remainder are all taken out.

 

Code steps

 

1. Define three variables to store the input minutes, the conversion hours, and the remaining minutes.
2. Get the input minutes from the interface
3. Calculation Result
4. output the result to the interface.

 

Code details

 

             //  1 Define three variables to store the input minutes, the conversion hours, and the remaining minutes.  //  2. Obtain the input minutes from the interface  //  3. Calculation Result  // 4. output the result to the interface.              Int  I, H, M; console. writeline (  "  Enter the number of minutes:  "  ); I = Int  . Parse (console. Readline (); H = I/ 60  ; M = I % 60  ; Console. writeline (  " {0} = {1} hour {2}  "  , I, H, m); console. readkey (); 

Running Effect

 

 

Author:Memories of lost youthSource:Http://www.cnblogs.com/lukun/The copyright of this article is shared by the author and the blog. You are welcome to repost this article, but you must keep this statement without the author's consent andArticleThe original text connection is displayed at an obvious location on the page. If you have any problems, you can useHttp://www.cnblogs.com/lukun/ Thank you very much for contacting me.

 

 

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.