C Language Blog Job--one or two-dimensional array

Source: Internet
Author: User
Tags array definition

C Language Blog Job--one or two-dimensional array one, PTA Lab Assignment Topic 1: Simplified insertion sort 1. PTA Submission List

2. Design Ideas
定义循环变量i,交换变量时的暂存变量t,第一行输入几个数据n,判断标志变量flag=0,插入的变量number输入n,定义一维数组num[n+1]为有序序列for i=0 to n-1    输入num[i]end输入要插入数for i=0 to n    如果flag为0且number>=num[i] 结束这轮循环,进入下一轮循环    否则交换num[i]和number并且flag 为1endfor i=0 to n    输出num[i]end
3. Code

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

Multiple errors
1: Found the insertion position, the last value of the exception
Analysis: Because I use continue, iterate the array, if number than num[i] small no longer skip the back of the statement, so can find the correct position, and just beginning to exchange out the numbers will be smaller than the number of subsequent, will continue to call down, but to the last one because, did not define the last digit, The comparison result cannot be determined, so the last one cannot be determined after sorting.
Workaround: Flag is introduced to determine if an exchange has been made and, once exchanged, has been exchanged until the end of the array

2: Bad format
Did not look closely at the topic, thought or the same as before, the last number no space, thought is right, or wrong
Workaround: The output followed by a space can be

Topic 2: Addition table of tables 1. PTA Submission List

2. Design Ideas
定义循环变量i,j,k,输入n和repeat输入repeatfor k=1 to repeat    输入n    定义二维数组array[n+1][n+1]    for i=0 to n        for j=0 to n            array[i][j]=0初始化数组为0        end    end    for j=1 to n        array[0][j]=j首列为递增数列    end    for i=1 to n        array[i][0]=i首行为递增数列    end    for i=1 to n        for j=1 to i            题目要求位置的数等于列数加行数        end    end    for i=0 to n        for j=0 to n            if首行首列输出+            else if到每行末或为0时,换行并结束该行输出            else                if 最后一个输出array[i][j]不加空格                else输出array[i][j]并占4个空格        end    end
3. Code

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

Format error
At first, all the output%-4d, the output looks the same, to the wrong format
Workaround: Add a few sentence criteria, let it in the last output of each line without spaces

Topic 3: Yang Hui triangle 1. PTA Submission List

2. Design Ideas
定义i,j,k为循环变量,n为输入的数输入n定义二维数组array[n][n]for i=0 to n-1    for j=0 to n-1        array[i][j]=0初始化数组    endendfor i=0 to n-1    array[i][0]=1第一列赋值为1endfor j=0 to n-1    array[0][j]=0第一行除第一个数赋值为0endfor i=1 to n-1    for j=1 to n-1        array[i][j]等于上一行数加左上方的数    endendfor i=0 to n-1    for j=0 to n-1        if为首行或行数和列数相等,输出array[i][j]换行,结束该行输出        else 输出%4d的array[i][j]    endend
3. Code

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

Format error
The topic says that each data occupies 4 columns, because the front topic, thought is%-4d, the result writes out after the format is wrong, has the way to remove the back extra space, or the format error
Solution: Looked at the classmate's code, realized where the error, quickly changed the right

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

Third, peer code peer review 1. Peer evaluation of the names of students

Li Jinyao

2. My Code, mutual evaluation of the student code


3. Where do I differ from my classmates ' code? What are the advantages? What style of code do you prefer? If the classmate code is wrong, please help to point out where the problem.
    • Different points:
      1. Array definition:
      My code is to enter the length and then define the array, the classmate's code is to define the length of the array, and then determine the scope of use, and he defined two arrays, I have only one.
      2. Rearranging the sequence of sequences
      I am working in the original array, and the classmate is transferring the number from the original array to the other array.
      3. Other different
      Classmate's code also added a few conditions to judge to achieve the function of the topic requirements, and my Code does not

    • respective advantages
      My advantage: Short code length, less use of arrays, definition of array lengths as required, saving memory usage
      The advantages of students: simple thinking, as long as the number of arrays transferred to Ning an array can be, than I also change the value of the original array, simple operation.

    • Code style
      I prefer my code to be brief, without judging the array as 0 o'clock, and the array is less defined and more efficient to use the array.

Iv. Study Summary of the Week 1. What did you learn? How do I store strings in 1.1 C?

Defining an array of character types

1.2 What is the end flag of a string and why do you want to end the flag?

End sign: ' + '
Reason: Defining a character array is because it is not possible to directly know the number of characters in a string, and usually defines a length that is much larger than the string to be deposited, so if there is no end flag, the array will all be traversed to stop, which could result in a run time-out or an unexpected error. So add the end flag after the range of characters you use.

1.3 What are the methods for string input?

Set CH as a character variable or an array name for a character array
1.SCANF ("%c", &ch); Enter a single character
2.ch=getchar (); Enter a single character
3.SCANF ("%s", ch), input string, without &, directly put array name, encounter space stop
4.gets (ch); input string, can absorb space

1.4 Numeric characters How to turn an integer, write a pseudo-code?

Single conversion: Numeric characters-' 0 '
Multi-bit conversions:
Suppose the character array has a[1]= ' 1 ', a[2]= ' 2 ', a[3]= ' 3 ', converted to 123
1. Define the loop variable i,sum=0
2.i=0
3. If a[i]!= ' + ', perform the following cycle
4.sum=sum*10+ (a[i]-' 0 ')
5.i++

1.5 16 binary, binary string how do I turn 10 binary? Write pseudo-code?

Assuming that the character array a[] is stored in each bit of the 16 binary number or binary number

    • 16 binary

1. Define the loop variable i,sum=0
2.i=0
3. If a[i]!= ' \ ' is the following cycle
4. If A[i] is a numeric character, then Sum=sum16+ (a[i]-' 0 ')
5. If A[i] is a-f, then sum=sum
16+ (a[i]-' a ' +10)
6. If A[i] is a-f, then sum=sum*16+ (a[i]-' a ' +10)
7.i++

    • Binary

1. Define the loop variable i,sum=0
2.i=0
3. If a[i]!= ' + ', perform the following cycle
4.sum=sum*2+ (a[i]-' 0 ')
5.i++

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

Although it will be a little bit of programming, but obviously feel that their code is not enough, the idea can not keep up, the same question to spend longer than others to write, and some errors to be adjusted for a long time to be completely correct, for the character array to use the scope of completely unable to grasp, submitted PTA Runtime error only continuously expand the array range.

The following are the wrong questions:

1. There are the following definitions: char x[]= "ABCDEFG"; Char y[]={' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' G '}; The correct narrative is ().
A, array x and Arrays y equivalent
B, arrays x and array y are the same length
C, the length of the array x is greater than the length of the array y
D, the length of the array x is less than the length of the array y
Answer: C, wrong choice b
Array, the characters are different from the length of the string stored in the array, and the string is automatically added with an end symbol ' \ s ' when it is stored in the array, so the string is one more length than the single character input

2. Enter 10 integers, sorted by selection method, and output in order from small to large.

#define  N   10main( ){int  i,j,min,temp,a[N];for(i=0;i<N;i++)scanf("%d",  【1】);printf("\n");for(i=0;  【2】;  i++){min=i;for(j=i;j<N;j++)if(a[min]>a[j])  【3】 ;temp=a[i];a[i]=a[min];a[min]=temp; }for (i=0;i<N;i++)printf("%5d",a[i]);printf("\n");}

Reference answer
&a[i]
I<n-1
Min=j
My answer &a[i] i<n A[min]=a[j]
It should be the subscript exchange.

3. Midterm Summary 3.1 Why do you think you didn't do well?

1. The title of the choice question is basically wrong in the more basic content, such as the correct definition of assignment statement, the priority of logical judgment, the scope and the life cycle of different types of variables, the shape of the function to participate in the argument, etc.
2. Write the program running results of the main problem is not familiar with the recursive algorithm, misjudged the number of outputs
3. The main mistake in the procedural blanks is the lack of proficiency in scientific notation and carelessness
4. The handwriting program is really not proficient, used to be programmed on the computer, handwriting can not be written all of a sudden
The basis is not clear, the choice of hesitation for a long time, the analysis of the program spent more time, indicating that there is insufficient code volume, resulting in the final program only with a shorter time to write, and its quality is not good. In short, the foundation is not firm, time is not arranged well.

3.2 List the wrong questions.

Select title:
After ignoring the B option, there is a | |, when && front 0 o'clock thinks the whole equation is 0, it actually has to be compared with the following formula, because | | The back is 1, so the whole equation is still 1.
Fill in the blanks questions:

The 7th empty only filled ch, but also add =getchar, when the character input is not familiar with, so fill it too fast is wrong
Change the wrong question:
Do when only found 4 errors, afraid of being deducted points, dare not to change, term=-termxx/(n+1)(n+2);//change to Term=-termxx/((n+1) (n+2));
Programming Questions:

Finish the previous question, the question is not much time left, so according to the previous written and this question similar to the code written over
Answer:

#ifndefFUNC#defineFUNC#include<stdio.h>#include<math.h>doubleFactorial(intnum);doubleCnr(intn,intr);#endifdoubleFactorial(intnum){inti;doublefac=1;for(i=1;i<=num;i++)fac*=i;returnfac;}doubleCnr(intn,intr){doublek;k=Factorial(n)/Factorial(r)/Factorial(n-r);returnk;}intmain(){intn,r;intx=15,y=0;doublek;printf("输入:");scanf("%d%d",&n,&r);while(n!=0||r!=0){}printf("输入:");scanf("%d%d",&n,&r);}printf("程序结束");return0;}
3.3 The second half semester how to adjust C's study?

Read the important knowledge of books, look at other people's good code, improve the speed of writing code and reading code.

C Language Blog Job--one or two-dimensional array

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.