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

Source: Internet
Author: User
Tags greatest common divisor

I. PTA Lab Assignment Topic 1:7-4 simplified insertion sort 1. PTA Submission List

2. Design Ideas

3. Code


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

The initial code is

But after submitting the show

Did not consider the maximum n, inserted in the tail and n equals 0 of the case, and then changed, but forget if n is 0 inserted in the head, or x>a[n-1] should be inserted in the tail, output x after the end of the program, resulting in an incorrect answer

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

2. Design Ideas

3. Code

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

At the beginning do not know Addend and summand how to output, thought can be output separately, so write the following code,

Output error, after asking the classmate, said the first line of + and addend can be output separately, and stored in the array and the number of columns of the summand loop output

But still output error, found that the problem is the output of the triangle, it is added to judge the condition i<j; but the format error after compiling

After re-reading the question, we find that there is no space at the end of the line, so when i=n-1

The topic 3:7-11 Two-point search Method 1. PTA Submission List

2. Design Ideas

3. Code

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

Compile-time input even when the display is not found, but the input is odd and can be found, but the position of one more, enter the number outside the array, the output is correct




Answer error showing output Yes after submission on PTA

In this way, the binary search, where the size of the M is the location, do not add one, after the correct answer

Second, this week's topic set PTA Final Ranking

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

Mutual Evaluation Students: Tianyachen
Topic of mutual Evaluation: 7-4 Simplified Insertion Sort

2. My code, peer-to-peer code (the core code here is good, not necessarily all the code, the figure indicates whose 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.

The biggest difference between me and the violin code is:
1. At the outset, the piano assigns X to a[n],x from the last digit of the ordered integer to start comparing
2. I am considering various situations (1) n=0; (2) n=1&&a[0]

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

1. String storage--array initialization, for example:
static char s[6] = {' H ', ' A ', ' P ', ' P ', y, ' s '}, the string "Happy" is stored in the array
(The string consists of a valid character and a string terminator ' \ S ')
2. Storage of strings--assignment and input
For example: static char s [80];
S[0] = ' a ';
S[1] = ' + ';
Using the assignment method, the string "a" is stored in the array s, and it is equivalent to the static char s [n] = "a";

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

The end flag of the string is ' + ' because the string does not show the number of valid characters, only the characters before the end of the string are valid characters of the string, usually by comparing whether the value of the array element is equal to ' + ' to determine whether to end the loop, that is, the Terminator ' + ' to control the loop

1.3 What are the methods for string input?

1. Direct input: scanf ("%s", str1)
2.gets (STR1)
3. Use the Loop while ((Str1=getchar ())! = ' + ')

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

Define number,i, for storing converted integers, defining arrays str[] for holding numeric characters
i=0;
while ((Str[i]=getchar ()! = ' \ n ') i++; str[i]= ';// input string
for (i=0;str[i]!= '; i++)//
Cycle condition: str[i] Not equal to ' \ n '
number=number*10+str[i]-' 0 '//convert to Digital
Output number

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

16 binary string goto 10 binary
Define I, the definition array hexad[80] is used for storing 16 binary strings, the definition of number stored into decimal results, number=0;
i=0;
Input string while ((Hexad[i] = GetChar ()) = ' # ')//Assume ' # ' as Terminator
i++;
hexad[i]= ' + '//string terminator is also stored in the array
for (i=0;hexad[i]!= '; i++) iterates through the entire array, converting one by one
if (hexad[i]>= ' 0 ' &&hexad[i]<= ' 9 '//If it is a numeric character of 0~9
Number=number16+hexad[i]-' 0 '
else if (hexad[i]>= ' A ' &&hexad[i]<= ' F ')//If it is a a~f capital letter
Number=number
16+hexad[i]-' A ' +10;
else if (hexad[i]>= ' a ' &&hexad[i]<= ' f ')//if it is a lowercase letter of a~f
Number=number*16+hexad[i]-' a ' +10;
Output number

2 binary string goto 10 binary
Define I, define array str[80] to hold 2 decimal numbers, define the result that number is converted to decimal
i=0;
The input string while ((Str[i]=getchar ())! = '% ') i++;
Traversal array Str[i]
for (i=0;str[i]!= ' n '; i++)
Number=number*2+pow (i,2)
Output decimal digit number

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

1. The use of a two-dimensional array is not very good, the conversion between the system is not very skilled,
2. The wrong questions in the class



    • Input is too careless, less dozen &; in the array of the first n-1 number in order to compare the size, so I

    • The defined C is a character type, input with C=getchar (), i=0, the output capital letter with i+65, representing asii code value

    • Give the initial value of J, J=0;sent is a string, the input with get (sent), i<80 to Sent[i]; When the input character is not C, the character is stored in another array, sent[j++]=sent[i]; The string terminator is also stored in the array sent[j];
3. Midterm Summary 3.1 Why do you think you didn't do well?
  • 1. Select title: The basic knowledge of the textbook is not strong enough, for the conversion between the concept of a clear,
  • 2 Analysis program: usually read too little code, resulting in leaving the compiler to read the program itself will understand the meaning of the wrong program
  • 3. Fill in the blanks and change the wrong: The usual code practice is too little, not very good response to the program needs to express the meaning of
  • 4. Programming: Write the program structure confusion, usually rarely with handwritten code, no compiler hint error point, resulting in error is unknown, there are usually written after the code is not very good review, resulting in the problem has been done wrong
    In fact, the main reason for the exam is not the most important factor is that their usual learning methods are not correct, the preparation of the work is not serious enough, leading to the knowledge of the foundation is not solid, the teacher said the topic did not review the timely, and do not miss the topic sometimes will forget to revise, resulting in the same mistake, Normal programming and code reading too little, so that a topic will be thinking for a long time, usually debugging a topic will take a lot of times, the efficiency of the problem is too low

    3.2 List the wrong questions.
  • Select title: 2. Convert hexadecimal number (1EB) 16 to decimal number;
    A hexadecimal number of a represents 10, then B means that 11,e represents 14, so this hexadecimal number is (11416) 16, converted to a decimalnumber of 1 16+1416+111=491;
  • Fill in the Blanks: 4. Enter future characters, count and enter the number of letters, numbers, and other characters

    Consider forgetting the English alphabet and capital letters, only consider the lowercase letters, so the mistake, re-answer 1.char 2. (Ch=getchar ()) 3. (ch> ' a ' &&ch<= ' Z ' | | ch>= ' A ' &&ch<= ' Z ')
  • Error: 1. A function Maxcommonfactor () is designed, and the greatest common divisor of two positive integers is calculated by Euclidean algorithm.

    The exam is not carefully read, resulting in a lot of mistakes did not find
    1.int maxcommonfactor (int a, int b) is a function declaration and should be appended with a semicolon at the end
    2.SCANF ("%d%d", A, b) input means to add &, i.e. scanf ("%d%d", &a,&b)
    3.x=maxcommonfactor (int a,int b) Here is the call function, not the definition function, should be changed X=maxcommonfacor (int a,int b)
    The 4.do while loop satisfies the condition before it enters the loop, so when the remainder is not equal to 0 o'clock in the loop, the while (r==0) should be changed to while (r! = 0)
    5. Finally, the assignment of B to the A,r is assigned to B, so after the loop is finished, a is dividend, that is, greatest common divisor at this time, B is the remainder
  • Programming Questions: 3. Write a function that takes the number of R numbers from n different numbers, with the number of values:

    In the exam, the handwriting code structure is too confusing, resulting in a low score

3.3 The second half semester how to adjust C's study?

Take every preview work seriously, master the basic knowledge, their own wrong or not to do the title in time to revise, increase the Code of Practice and reading volume, as well as the usual form of the habit of looking at the blog, refer to other people's ideas, learn from the good students learning methods and solutions to the problem, do not spend too much time on a topic, If you have not thought for a long time, you can refer to the students ' ideas, re-write the code according to their own understanding, improve the learning efficiency

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.