C Language Blog Job-data type

Source: Internet
Author: User
Tags array definition array length

First, the PTA laboratory work Title 1: Print diamond pattern 1. PTA Submission List

2. Design Ideas

Define shaping variables n,t, loop variable i,j
Enter the value of n
If N!=1
Then for I=1 to I<= (n+1)/2
For J=n+1-2I to J>=1
Output spaces
End J
For T=1 to t<=2
End T
Output \ n line break
End I
For I=1 to i< (n+1)/2
For j=1 to j<=2
Output spaces
End J
For t=1 to T<=n-2i

End T
Output \ n line break
End I
When N=1
Then for I=1 to I<= (n+1)/2-1
Output spaces
End I
Output * and a space

3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.
    • Did not find the pattern of the second half of the diamond, the answer and examples are the same, but the other digital input is not a diamond.
    • There is no discussion of the special case when the number of inputs is 1, and it is found on the PTA prompt when submitting.
Topic 2: The number falling into the trap 1. PTA Submission List

2. Design Ideas

Define shaping variables n,sum,i=1,item1,item2//sum represents the sum of the numbers added, Item1 used to hold the nth number, item2 to hold the number of n+1
Enter the value of n
Sum assigns an initial value of 0
T=N;//T is used to store the nth number
While n!=0//ask for numbers and
End While.
The value of sum is assigned to ITEM2//ITEM2 to hold the number of n+1
Values for output I and sum
Sum is assigned a value of 0 again
While X!=item1
End do.

3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.
    • When I first wrote, I misunderstood the test instructions, and thought it was the sum of the numbers. The step is only executed at the first time.
    • Do not know what the condition of the end of the while loop, and finally defined two variables to record the value of the front and back two numbers, do not know if this will be more troublesome.
Topic 3: Simple Calculator 1. PTA Submission List

2. Design Ideas

Define shaping variable Number,sum,flag initial value is 0
Defining the character variant op
Enter a value for sum
While OP is not equal to ' = ' established
then enter a character
If op equals ' = '
flag=0; end Loop
else if op equals ' + '
else if op equals '-'
else if op equals ''
else if op equals '/'
If number==0
The flag=1; end loop

End While Loop

If flag==0
Output Sum final value
Output "ERROR"

3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.

The first time I wrote I did not output a number in the loop, but directly in the loop output a number and character, and then loop. The Commit display section is correct, because I have this code that cannot output results when you enter only one number and an equal sign. If I enter ' 1 = ', the number of ' 1 ' to be output, and the code I write cannot be implemented, so put a number outside the loop.

Second, this week's topic set PTA Final ranking.

PTA Rankings

Iii. Summary of this week's study 1. What have you learned? 1.1 How is a one-dimensional array defined and initialized?
    • Defines an array that requires explicit array variable names, the type of array elements, and the size of the arrays. The general form is type an array group name "array Length". Arrays can be initialized at the same time as they are defined. The form is given a constant value table with a pair of curly braces, and the system initializes the array elements in a subscript order (in order of storage). The number of constants given cannot exceed the length of the array definition. If the number of given constants is insufficient, the system initializes the remaining elements to 0 values.
1.2 A one-dimensional array in-memory structure? can draw a description. What does an array name mean?
    • After the array is defined, the system allocates a contiguous storage unit in memory based on the type and number of elements in the array for storing the elements in the array and sequentially numbering the cells, that is, subscripts, to distinguish between different cells. The number of bytes required per cell is determined by the type given when the array is defined.
    • The C language specifies that the array name represents the address of the first cell in the contiguous memory space allocated by the array, that is, the first address.
1.3 Why use arrays?

Using an array makes the program simple and avoids the hassle of defining multiple variables. Defining an array can save memory. 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 display.

Define variable n,,temp, loop variable i,j
Define Array A[n]
Fori=0 to I<n
Enter the value of A[i]
End I
For I=0 to I<n-1
For J=i+1 to J


Define variable a[n],,temp, cyclic variable i,j;
For (I=0 to I<n.
Enter the value of A[i]
End I
For i=0 to I<n//bubble sort
For J=0 to J


For I=0 to I<n.
Enter the value of A[i]
End I
For I=1 to I<n
if (A[i]

End I

1.5 Introduction What is the binary lookup method, which differs from the order lookup method?

Binary Lookup method: Determines the midpoint position of the interval: mid= (low+hight)/2

(1) Compare the number of unknown origin with the midpoint, and if it is equal, the search succeeds. If Mid> is looking for a number, set the number to the right of the mid and the number to the left of the mid to a new sequence. Make high=mid-1.

(2) If mid is less than that number, leave the number on the left of the mid and set the number on the right side of the mid to a new sequence. At this time low=mid+1.

(3) Repeat steps (1) and (2).

(4) If low>high, the same number is not found in the sequence.

    • The sequential lookup method is to compare a number to a series by one, and the search efficiency is low.
    • The binary lookup method must be a sequential sequence, and the order lookup method is not required.
1.6 How are two-dimensional arrays defined and initialized?
    • Two-dimensional arrays are defined as: Type an array group name "line Length" "Column Length"

    • Two ways of initializing: 1 branch assigns the initial value, the general form is: Type an array group name "row Length" "Column Length" ={{Initial value table},,{initializer table k},} ;

2 Sequential Assignment method, the general form is: Type an array group name "line Length" "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.
    • To achieve a matrix transpose simply place the subscript I, J, into J, I, i.e. exchange all A[i][j] and a[j][i].

    • Lower triangle: i>=j

    • Upper triangle: i<=j

    • Symmetric matrix: A[i][j]==a[j][i]

1.8 What is the general application of a two-dimensional array?
    • Mainly used to represent two-dimensional tables and matrices.
2. This week's content, you are not what?

In PTA, the 9th segmentation expression and the 8th question judge the legal identifier is not written.

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.