Data-course 1st-door to advanced masters

Source: Internet
Author: User

Lesson 1st-the door to advanced masters

 

  1. Understanding the nature of a program

Programs exist for actual problems. Essentially, programs are steps to solve the problem.

Problem:

How to put elephants in the refrigerator?

(1) open the refrigerator door (2) Put the elephant in (3) Close the refrigerator door

Elephan * E = getelep ();

Int F = open ("fridge ");

Put (F, E );

Close (F

 

  1. First understand the actual problem

(1) confirm the problem type.

For example, calculate the number of minimum values.

(2) confirm the solution steps.

For example, open a file, read data, close a file, computation, and.

 

Let's look at a program that calculates the sum of the First n items:

# Include <stdio. h>

# Include <malloc. h>

Long sum1 (int n)

{

Long ret = 0;

Int * array = (int *) malloc (N * sizeof (INT ));

Int I = 0;

For (I = 0; I <n; I ++)

{

Array [I] = I + 1;

}

For (I = 0; I <n; I ++)

{

RET + = array [I];

}

Free (array );

Return ret;

}

Long sum2 (int n)

{

Long ret = 0;

Int I = 0;

For (I = 1; I <= N; I ++)

{

RET + = I;

}

Return ret;

}

Long sum3 (int n)

{

Long ret = 0;

If (n> 0)

{

Ret = (1 + n) * n/2;

}

Return ret;

}

Int main ()

{

Printf ("% d \ n", sum1 (100); // 5050

Printf ("% d \ n", sum2 (100); // 5050

Printf ("% d \ n", sum3 (100); // 5050

Return 0;

}

 

  1. Program Evaluation

(1) use up a small amount of memory space to solve the problem

(2) step-by-step solution

Excellent developers need to pursue the high "cost-effectiveness" of code "!

 

Summary:

(1) The program is stored for specific problems.

(2) The program should solve the problem.

(3) The same problem can be solved in many ways.

 

 

 

 

 

 

 

 

 

 

 

 

Data-course 1st-door to advanced masters

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.