C Language Blog Job-data type

Source: Internet
Author: User
Tags array definition array length

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

2. Design Ideas
  定义变量row,bit,number;  定义字符型变量r,p;  输入number  取出后两位数bit=number%100;  取出前两位数row=number/100  r=row+160;b=bit+160;  putchar(r);putchar(b);输出
3. Code

4. Problems encountered in commissioning process and PTA submission List status note

The idea clear, PTA submitted once over, and no debugging problems.

Topic 2: Print diamond pattern 1. PTA Submission List

2. Design Ideas
    定义变量n,i,j;    输入n;    for i=0  to    n/2       for j=1    to    n-1-2*i  输出空格  end       for j=1    to    1+2*i     输出*加空格  end       换行   end    for i=1   to    n/2       for j=1    to   2*i     输出空格   end       for j=1    to   n-2*i    输出*加空格   end       换行   end
3. Code

4. Problems encountered in commissioning process and PTA submission List status note

Submitted to PTA prompt format error, running results such as, and did not find any problems;

According to experience, the format error may be the output of a space some problems, so the space for the # number output, the results such as

Found that the first column has a space, and the title is not, after discovering the problem change the corresponding J start value, eliminate the first column of space.

Topic 3: Simple Calculator 1. PTA Submission List

2. Design Ideas

Main function:
Define variable Number1,number2,sum, character variant op
Enter the Number1 and assign the value to sum
While OP is not equal to =
Input number2
If number2 = = 0 && op = = '/'
Output error, end program
If OP is a arithmetic character
If it is, call the function operation and assign the value to Number1
Otherwise, output error, end program
End
Output sum
Operation function:
Define the variable sum
Switch (OP)
OP is +,sum = Number1 + number2;
OP is-,sum = Number1-number2;
OP is , sum = number1 number2;
OP is/,sum = Number1/number2;
Returns the value of Sum

3. Code

4. Problems encountered in commissioning process and PTA submission List status note

Before submitting the first two hints compile error, immediately thought I scanf wrote scanf_s, because then I was using vs to write this question, do not know why vs prompts me to use the scanf_s input;

So I just one tune, when the output is 0 when only one operand is lost, so I assign the first operand to sum, which solves the problem, when the denominator is 0 o'clock, when the error is output, it just jumps out of the loop through break, or continues to output the value of sum, The break is replaced by return 0, and the illegal character is the same as the direct end loop.

Second, this week's topic set 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 an array definition is: Type an array group name [array length];
Initialization: Type an array group name [array length]={initial value table}; The initial value table is the initial value of the array; initialization can also be directed to some elements; if the static array is not initialized, the system automatically assigns 0.

1.2 A one-dimensional array in-memory structure? can draw a description. What does an array name mean?


The array name represents the address of the first cell in the contiguous memory space allocated by the array, which is the first address.

1.3 Why use arrays?

The use of arrays in the program, you can let a batch of the same type of variables using the same array variable name, subscript to distinguish each other, simple expression, readability, easy to use the loop structure.

1.4 Introduction to the selection method, bubble method, direct insertion sort how to sort? Pseudo code display.

1. Selection Method:
Define variable i,index,k,n,temp;
Enter n, define array a[n], use the loop to enter n values, and then assign each element of array a
For K=0 to K<n-1
index=k;/ Store Minimum subscript/
For I=k+1 to N
If a[i] less than A[index]
If it is, then Index=i end
Temp=a[index];a[index]=a[k],a[k]=temp the smallest element and the element with the subscript K swap End
Output n The value of the number of array elements
2. Bubbling method:
Defining Variables I,j,k,n
Enter n, define array a[n], use the loop to enter n values, and then assign each element of array a
For I=0 to N-1
For J=0 to N-i-1
If A[J] greater than a[j+1]
Interchange a[j] and a[j+1]
End
Output n The value of the number of array elements
3. Direct Insert Sort
Defining Variables I,j,k,n,temp
Enter n, define array a[n], use the loop to enter n values, and then assign each element of array a
For I=1 to N-1
For J=0 to I-1
If A[J] greater than a[i] jump out of Loop end
If j is not equal to I-1
temp=a[i]//to move data larger than A[i] back
For K=j to I-1
A[K+1]=A[K] End
a[k+1]=temp//put A[i] in the right place
End
Output n The value of the number of array elements

1.5 What is the binary search method? It differs from the order lookup method?

The basic idea of binary search is to divide n elements into roughly equal two parts, take A[N/2] and X to compare, if X=A[N/2], then find X, the algorithm aborts, if X<A[N/2], as long as the left half of the array a continues to search X, if X>A[N/2], Search for x in the right half of the array A.
Difference: The binary lookup method only applies to an ordered set of numbers, which is binary lookup when searching, and the sequential lookup method also applies to unordered arrays, comparing the number to be searched and the number of this group to find out the location.

1.6 How are two-dimensional arrays defined and initialized?

Definition: Type an array group name [line length] [column length]
Initialization: Type an array group name [line length] [column length]={{Initial value table 0},,{Initial value table k},}, can also be assigned in order; two-dimensional array initialization can also be done for some elements

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 indicate

To exchange A[i][j] and A[j][i] by looping the ranks of matrices;
Lower triangle: i<=j Upper triangle: i>=j symmetry 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 with rows and columns of the representation

2. This week's content, you are not what?


This problem I do not understand when the end is used to achieve what, so did wrong, later only found that the original is the conversion into the system;

It's too careless to see the C option, D.

C Language Blog Job-data type

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.