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

Source: Internet
Author: User

First, the PTA laboratory work problem 1:7-7 find saddle point 1. PTA Submission List

2. Design Ideas
{       定义变量n,j,i,flag1,flag2    输入阶数n    定义n阶二维数组a[n][n]    for i=0 ;i<n ; i++{         for j=0 ;j< n; j++            输入数据a[i][j];            }     for i=0 ;i<n ; i++{         for j=0 ;j< n; j++            初始化判断flag1=0;flag2=0;             for k=0 ;k<n ;k++{                if 该行中有比a[i][j]更大的数据                    flag1=1;                if 该列中有比a[i][j]更小的数据                    flag2=1;            }            if flag1=flag2=0 {                 输出鞍点位置 i ,j                结束程序            }    }    if flag1,flag2不全为0{        输出 NONE        结束程序    
3. Code

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

Encountered the problem: at the beginning of the value of looking for saddle point, forget to consider the situation of the saddle point does not exist, not with the flag to judge, after the use of flag to find the saddle point after the end of the program has not ended and output the None

Workaround: End the program directly after the output saddle point location

Topic 2:7-8 addition tables 1. PTA Submission List

2. Design Ideas
{    定义变量repeat,number,n,i,j,flag    定义二维数组a[10][10]    输入总次数repeat    for  ;repeat>0 ;repeat-- {        输入最大加数n;        初始化数据number=1        输出加号‘+‘;        for i=1 ;i<n ;i++{            赋值让第一行第一列都为 1 2 3 ... n        }        for i=1 ;i<n;i++ {            for j=1;j<=i;j++                计算下上角的数值,等于该元素所在行的第一个数加所在列的第一个数        }        for i=0,j=1;i<n;i++            输出第一行除加号外身剩下的数据,最后一个输出后换行         for i=1; i<n;i++{             for j=0; j<i;j++                输出下三角的数据,在输出对角线数据时换行          }  
3. Code

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

Problem encountered: The value of number is not initialized at the start of each loop, resulting in an error in the next round of loops

Workaround: Each cycle begins with a seasonal number=1

Topic 3:7-10 Yang Hui triangle 1. PTA Submission List

2. Design Ideas
{    定义数组n[100][100]    定义变量n ,i,j    输入n    for i=0 ;i<n ;i++{        for j=0 ;j<n ;j++            初始化数据n[i][j]=0    }    for i=0 ;i<n ;i++        赋值第一列全为1 n[0][i]=1     if n>0&&n<10{        for i=1;i<n;i++{            for j=1;j<n;j++            /*每个数据等于该数据上一行数据加上左上方的数据 */            a[i][j]=a[i-1][j]+a[i-1][j-1];        }        for i=0;i<n;i++{            for j=0;j<=i;j++                输出数据n[i][j]            换行 putchar(‘\n‘);         }    }    
3. Code

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

Encounter problem: only make a[0][0]=1; the loop starts from j=0, although there is no problem with the output, but there is a[i][j-1 in the loop] causing the array to go out of bounds

Workaround: Make the first column 1 so that you can start the calculation from J=1 without causing the array to go out of bounds

Second, this week's topic set PTA Final Ranking

Third, peer code peer review (1 points) 1. Mutual evaluation of the names of students

Zhu Jiewei

2. My code, peer-to-peer code (the core code here is good, not necessarily all the code, the figure indicates whose code.) )

My Code:

Classmate 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: My code uses a two-dimensional array, and the students used two to think of the array, I calculate the value of the triangle, the direct use of a[i][j]=a[i-1][j]+a[i-1][j-1], and Zhu students through the j,i to determine the corresponding value
Each of the advantages: My code is more concise, directly calculated in addition to the first column of each group, Zhu's code with a branch of judgment on each case to calculate
What kind of code style do you prefer: Prefer my code style, my code is simpler, and the process of judging and calculating is less

Iv. Summary of the study this week (3 points) 1. What have you learned? How do I store strings in 1.1 C?

Defining character Array Storage

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

The end of the flag bit ' \ n '; If the length of the input string is not known, the string can be determined to be ended

1.3 What are the methods for string input?

Three kinds.
-scanf ("%s", a), enter a string that ends with a space
-scanf ("%c", &a[i])/(A[i]=getchar ()), using a loop to enter each character
-Gets (a), enter a string that ends with a carriage return

1.4 Numeric characters How to turn an integer, write a pseudo-code?
{    ...    初始化sum=0;    for i=0 ;a[i];i++{        if a[i]为数字字符            sum=sum*10+(a[i]-‘0‘);     }    
1.5 16 binary, binary string how do I turn 10 binary? Write pseudo-code?

16-in-turn 10-system:

{    ...    初始化sum=0;    for i=0 ;a[i];i++{        if a[i]为0到9             sum=sum*16+(a[i]-‘0‘);        if a[i]为a到f             sum=sum*16+(a[i]-‘a‘+10);        if a[i]为A到F             sum=sum*16+(a[i]-‘A‘+10);    }    

Binary goto decimal:

{    ...    初始化sum=0;    for i=0 ;a[i];i++{        if a[i]为‘0‘或‘1‘             sum=sum*2+(a[i]-‘0‘);    }    
2. This week's content, you are not what?

The wrong questions in class:


The topic to the meaning of the question did not understand clearly, that the judge is the substring and the number of the same letter string, when Str2[k]!=0, count++

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

This exam did not test well, not because the problem is how difficult, but because of some of their own reasons:

    • Do not pay attention to this exam, think will do PTA can test the wrong number of ideas
    • Basic knowledge is not solid enough, choose to drop points too much, the analysis of options is not in place
    • Usually the code has a problem too rely on debugging tools, a look at the wrong answer to start debugging, can not read the code to find errors
    • Not in-depth review before the exam, just simple to do a bit of last year's paper, a simple turn over the book, for a lot of focus has not been reviewed, there are some knowledge points have not been clarified, such as bit arithmetic.
    • The reading of the topic is not careful enough, some of the topics could have been scores, but because the problem is not careful enough, resulting in wrong
    • Do the problem when a little impatient, especially programming problems, a see the topic began to write directly, should first make a simple draft, the framework is written well
3.2 List the wrong questions

Select title:
16. What is the number of executions for the following for loop? For (x=0,y=0l (y=3) && (x<=4); x++,y++)
The correct answer to this question is 5 times. Because I did not notice that there is only one ' = ' in the y=3, this is an assignment statement is constant, think more, to consider the content of the loop, choose not sure how many times.

Fill in the blanks questions:
9. Correct answer: 1.0/(i*i), I wrote the wrong variable, written 1.0/pow (t,2)

Change the wrong question:
X=maxcommonfactor (int a,int b); X=maxcommonfactor (A/b);
Not familiar with the parameters of the function, this error has not been changed.

Programming Questions:
Game of guessing:
Error point: The generation of random numbers will not be written, the topic requires "until the operator wants to stop the end" did not write.
Add a statement that generates a random number: Srand (time9null)); rand ()%100+1;
Apply the Do-while loop when input 0 o'clock ends.

3.3 The second half semester how to adjust C's study?
    • First of all, I should get rid of the bad habit of not reading the subject carefully. Sometimes I tend to look at the front of the topic to the back of the problem to write, but it is a lot of wrong. This may also be related to the skill of answering. In the future, whether in the classroom or PTA or the examination should be serious examining, self-study reading questions, the topic to see the right, optimistic. Time permitting, you have to check a few times, and never allow yourself to make a mistake like this.
    • Preview of the content of the book must be serious reading, to some of the key things to mark, for not understand the example can be knocked on their own, debugging to see the running process
    • It's important to review. But do not have to review every day, after all, we do not have so much time, but after each lesson must be carefully reviewed. can also accumulate knowledge of learning, use the weekend time to review
    • Later write code error is as far as possible to find their own, more use printf to check the wrong, really do not see out again to debug

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

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.