C-language jobs-data types

Source: Internet
Author: User
Tags array definition array length

First, the PTA experimental work Title 1:7-4 print diamond pattern 1. PTA Submission List

2. Design Ideas
定义整型变量 n,i,space,m,q,其中n表示行数,space表示空格输入一个奇数n    菱形上半部分    space=1            满足space<=(n+1)/2-i           space递增,实现循环输出空格           m=1           满足m<=2*i-1           m递增,实现循环输出星号后跟空格      循环结束后换行      菱形下半部分    space=1       满足space<=i-(n+1)/2        space递增,循环输出空格      q=1       满足q<=2*n-2*i+1       q递增,实现循环输出星号后跟空格           循环结束后换行            i递增,直到不满足i<=n           return 0;
3. Code

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

Mainly on the format problem, obviously regardless of how to lose is the correct pattern, submit always show is a format error ... Including line breaks, including spaces are taken into account, but the pattern is more bizarre. From the beginning of the code analysis, it is found that the use of the IF statement to realize the end of the loop wrap is completely redundant, converted into a loop body plus an output line-break can achieve the effect we want. After deletion, the submission is displayed correctly.

Topic 2:7-6 falls into the number of traps 1. PTA Submission List

2. Design Ideas

function declaration int Fun (int a);
int I,n0, where N0 represents the first number
Input N0
int a[3000];
Assigns the value of the N0 to the first element of the A array
Call the function to calculate the fun (N0) and assign it to a[i]
i=2;
Meet requirements A[i-1]!=a[i-2], output lines i-1 and A[i=1]
Does not satisfy the condition, executes A[i]=fun (a[i-1]), I increments

function int fun (int a)
Defines the variable ones represents the end number, sum represents each number and the result represents the calculated results
sum=0;
When a does not wait for 0 o'clock
Calculates the trailing digit ones=a%10;
Remove the trailing digit A=A/10;
The numbers and sum=sum+ones;
The result of calculation is result=sum*3+1;
Returns the result of the calculation

3. Code

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

This topic did not encounter any problems, mainly is the use of the newly learned array, not very familiar with, write down how to write it
After reading the topic, it is important to find the subscript, and the array is especially suitable for the subscript, so the array is selected. In addition, the process of calculating results is repeated, and the use of functions is chosen to make the calculation code clearer by referencing the function.

Topic 3:7-10 Simple Calculator 1. PTA Submission List

2. Design Ideas
定义俩个整型变量 m,n;定义整型变量 result表示是计算结果定义字符型变量opscanf("%d",&m);result=m;读入的字符不是等号时    scanf("%d",&n);        如果字符为 ‘+‘:result=m+n;跳出循环         如果字符为‘-‘:result=m-n;跳出循环         如果字符为 ‘*‘:result=m*n;跳出循环         如果字符为 ‘/‘:            如果n不为0                计算result=m/n;            如果n为0,输出ERROR,程序结束         如果字符不是加减乘除 printf("ERROR"),程序结束                   m=result                       输出result                           程序结束
3. Code

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

Problem: The input character is not determined after input m = this condition

WORKAROUND: Add if statement, judge the input character is =, but run to find this problem is solved, but the normal input, the result is error, after debugging found directly jump to default this branch, output error. You can assign m to result, you can implement output similar to 1=1.

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?

A one-dimensional array defines the general form: Type an array group name [array length] such as int a[10]
(1) Type name specifies the type of each element in the array
(2) The array name is the name of the array variable and is a valid identifier
(3) array length is an integer constant expression that sets the array size

Initialization
There are several elements in the array, you can give the initial value of each array in {}, separate the initial values with commas , and assign the initial order of {} to each element sequentially.
Note: the number of initialized data must not exceed the number of array elements, otherwise an error, such as int a[4]={1,2,3,4,5} is wrong

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

The array name is an address constant that holds the first address of the array memory space

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 . Simple expression, good readability, easy to use loop structure

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

(1) Sorting by selection method

Defining an Integer variable i,index,k,n,temp,index the subscript where the minimum value is stored
Define Array a[10]
Input n
I=0
When i<n, input number, I increment
Assigns the number of inputs to the N elements of array A in turn
K=0;k<n-1, use index to store the lowest value subscript
Determining the size of elements and A[index] in array a
If a[i]<a[index],index=i, the smallest element is exchanged with the element with the subscript K
Temp=a[index];
A[INDEX]=A[K];
A[k]=temp;
The value of the n array element after the output is discharged

(2) Bubble method sequencing
Define Array A[n]
Defining integer Variables I,j,temp,n
I=0
When meeting i<=n-1
Number of inputs
i++
Assign this set of data to a[n] in turn
Judge the two adjacent data, if A[J]>A[J+1]
TEMP=A[J]
A[J]=A[J+1]
A[j+1]=temp
A process like this has to repeat n=q-i times.
Output a new array after the loop ends

(3) Ordering by direct insertion
Define Array A[n]
Defining integer Variables I,j,k,temp
i=0;
When meeting i<=n-1
Number of inputs
i=0;
Temp indicates the minimum value of the corner label
Determine the size of data a[j] and TEMP
If Temp<a[j],a[j]=temp
Using a[k+1]=a[k] To move the data to the right after the insertion position
Repeats n-1 times, outputs a new array

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

Find in a set of ordered numbers, pass the corresponding data, compare the same data as the metadata, and then return the corresponding array subscript

Difference: Sequential lookups are characterized by a search down from the first element , and if the element is consistent with the target, the lookup succeeds if there is still no target element to the last element, then the lookup fails. The binary lookup is to find the target element from the middle of the table , if a consistent element is found, and if the intermediate element is smaller than the target element, the second half of the table is searched, and the middle element is larger than the target element, then the first half of the table is looked up.

1.6 How are two-dimensional arrays defined and initialized?

Two-dimensional array definition form: Type an array group name [President] [column length]

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},...}
Assigns all the data in the K in the initial value table to the element of the K row in turn

(2) Sequential assignment method
General form: Type an array group name [President degree] [column Length] = {Initial value table}
The data in the initial value table is assigned to the element in sequence based on the order in which the array elements are stored in memory.

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.

Row subscript and column subscript interchange. 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?

(1) Transpose of the Matrix
(2) To find the maximum element value and its determinant number

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

Start to contact pseudo-code, understand the meaning of code, but not familiar with how to express the pseudo-code, writing is very confusing, especially like bubbling, inserting, order sort this, look at the above to know what is the state of a

C-language jobs-data types

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.