C Language Blog Job-data type

Source: Internet
Author: User
Tags array definition array length case statement

First, the PTA experimental work Title 1:7-2 Location Code Input Method 1. PTA Submission List

2. Design Ideas
    • 1. Define integer variable a,h,l store location code, high byte and low byte respectively
    • 2. Enter a
    • 3.h= Location Code A of the first two bits +160,l= location code A after two bit +160
    • 4.putchar (h), Putchar (L)
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description. (1) The definition of two integer variables A and B, respectively, the region code and the code to enter the input need to input two numbers and the problem caused by the answer error solution: Only define a variable to represent the location code and then the first two digits of the area code after the two representation of the Code Title 2:7-7 Send red envelopes 1. PTA Submission List

2. Design Ideas
    • 1. Define an integer array a[7] deposit the 100,50,20,10,5,2,1 amount of money, variable m deposit bonus amount, R storage number
    • 2. Enter M
    • 3.for i=0,i<7,i++
      R←m/a[i];
      Output xx yuan: xx zhang \ n
      M←m-r*a[i];
      End
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description. (1) to start with nested loops and if statements to do, the real implementation of the cumbersome solution: using an integer array to hold each amount of money (2) does not define the output format, so that the answer format error Resolution: Define the output format left alignment Topic 3:7-10 Simple Calculator 1. PTA Submission List


S

2. Design Ideas
    • 1. Define the variable, a, and the operand, the character variable ch storage operator, cnt=1,cnt the judgment operator and the denominator is reasonable, result storage results
    • 2. Enter A,result←a,
    • 3.do
      Input CH
      If ch≠ ' input b
      Switch (CH)
      Ch= ' + ' result←a+b a←result break
      Ch= '-' result←a-b a←result break
      Ch= 'result←ab a←result Break
      Ch= '/' If b≠0 result←a/b a←result
      Else output Error cnt=0
      Break
      Default if ch≠ ' = ' Output error cnt=0 break
      If cnt=0 break
      While ch≠ ' = '
      End
      If cnt=1 output result
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description. (1) An error occurs when there is only one operand

Workaround: Assign the value of a to result before entering the loop and add the variable CNT to determine whether to continue entering the next operand (2) The value of Result=a+b,a has not changed, resulting in an incorrect answer.

Workaround: Add A=result in each case statement to achieve the cumulative calculation of result two, this week's topic set of PTA Final ranking.

Iii. Summary of this week's study 1. What have you learned? 1.1 How is a one-dimensional array defined and initialized? The general form of a one-dimensional array definition: Type an array group name "array Length" initialization is the assignment of the initial value, for example, int a [3]={1,2,3} is to a[0] to a[2] respectively in order to assign the initial value. Static arrays are automatically assigned a value of 0 if they are not initialized, and the value of the dynamic element is indeterminate if it is not assigned the initial values. If all elements are assigned an initial value, the amount can be omitted array length 1.2 One-dimensional array in-memory structure? can draw a description. What does an array name mean? The C language specifies that the array name indicates that the array allocates the address of the first cell in contiguous memory space, which is the first address. As long as you know the address of the first element of the array and the number of bytes required for each element, the storage address of each element can be computed. 1.3 Why use arrays? Using arrays in your program allows you to use the same array variable names for a group of variables of the same type, using subscripts to differentiate between them. His advantages are simple expression, good readability and easy use of loop structure. 1.4 Introduction to the selection method, bubble method, direct insertion sort how to sort? Pseudo-code Presentation-selection method
定义整型变量i,index,k,n,temp分别存放循环次数,最小值所在下标,所交换的下标,正整数个数,交换中介数,定义数组a[10]存放10个正整数输入整数nfor(i=0;i<n;i++)    输入a[i]的值for(k=0;k<n-1;k++)    最小值所在下标←k    for(i=k+1;i<n;i++)        IF a[i]<a[index],最小值所在下标←i;        最小元素←→a[k]end
Bubbling method
定义整型变量i,j存放循环次数,n存放整数个数,定义数组a[10]输入nfor(i=0;i<n-3;i++)    for(j=0;j<n-2;j++)IF a[j]>a[j+1]a[j]←→a[j+1]end
Sort by direct insertion
定义变量k,i,j循环次数,n存放整数个数,数组 a [ i ];for( i =1 ;i<n;i++)    for( j= i-1;j>=0;j--)IF a[j]<a[i] breakIF (j!=i-1)   for(k=i-1;k>j;k--)a[k+1]←→a[k]end
1.5 What is the binary search method? It differs from the order lookup method? Binary Search Method:

Premise (data is from small to large or from large to small sort)
① first find the number in the middle of the array to determine whether it is the number to look for.
② if not, judge the relationship between it and the number to be searched.
If the ③ is larger than the number that is being searched, the subscript of the middle number is returned, and the step ①② is resumed on the left.
If the ④ is less than the number that is being searched, the subscript of the middle number is returned, and the step ①② is resumed on the right.
Difference:
① binary search method is applied to the sorted array, which is fast.
The ② sequential lookup method does not require the array itself, but the arrays are inefficient when they are large.

1.6 How are two-dimensional arrays defined and initialized? Defined:

The form of a two-dimensional array definition: Type an array group name [length of the line] [column lengths]
Initialization
(1) Initial value of branch assignment
General form: Type an array group name [President degree] [column length]={{initial value table 0},...,{initial value table K}, ...} ;
(2) Order assignment initial value
General form: Type an array group name [President degree] [column length]={initial value table};

1.7 How is the matrix transpose implemented? In the matrix: the relationship between the row label I of the lower triangle, the upper triangle and the symmetric matrix J? Please state. Matrix Transpose: That is, the row subscript of an array is interchanged with the column subscript of an array, interchange a [i] [j] and A [j] [i]

Upper triangle: i≤j
Lower triangle: i≥j
symmetric matrices: A [i] [j] =a [j] [i]

1.8 What is the general application of a two-dimensional array? Generally used for lists and matrices 2. This week's content, you're not what?
    • (1) Not very skilled in defining arrays in functions
    • (2) PTA 7-9 do not know how to judge () whether it is an expression or a negative

C Language Blog Job-data type

Related Article

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.