C Language Blog Job--character array

Source: Internet
Author: User

One, PTA laboratory work. Topic 1:7-1 string converted to decimal integer 1. The results of PTA experiment

2. Design Ideas

3. Code


4. Problems encountered during commissioning and solutions
    • The problem encountered:

      • Should be output '-' should be out of the loop, but straight down, so that all the minus will be output

      • The following should be added with a minus sign before its number should be output

    • Workaround: Add the first minus sign to enter the next array, but not into the next array, at the output if there is a minus sign first output minus, in the output number.

Topic 2:7-4 Identification of Identity card 1. PTA Experiment Results

2. Design Ideas
    • 1. Define array a[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2},b[100]={0};z[11]={0,1,2,3,4,5,6,7,8,9,10} Define character array m[11]={' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 '};ch[100][100]; define a variable N,x=0,r

    • 2. Enter the value of N and define the i,j=0,sum=0,count=0;

    • 3.for (i=0;i<n;i++) {j=0, input ch[i][j] until the input is ' \ n ', j + +; until the outer loop loop ends

      1. for (i=0;i<n;i++) {sum=0;r=0;x=0;
        for (j=0;j<18;j++) {if ch[i][j] is not a 16-based representation of the number or letter, then X=1, exiting the inner loop;
    • 5. if (j<17,sum=sum+ (ch[i][j]-' 0 ') *a[j], perform the above cycle until the end;

    • 6. If X!=1,r=sum%11 calculates the r modulus value; for (j=0;j<11;j++) {if z[j]==r and m[j]==ch[i][17],count++;b[i]=1; exit this loop.

      1. If count==n) {printf ("all passed", otherwise output each identity card, note that if the value of B[i] is 0, then go directly to the next loop and wrap each time after the inner loop ends.
3. Code


4. Problems encountered during commissioning and solutions
    • The problem encountered:

      • You should enter a 17 number and enter the next loop, and he just loops 16 numbers and outputs it directly.

      • The output value n=100, directly stop the operation, the scope of the problem

    • Workaround: Re-delimit the scope.

Topic 3:7-10 positive integer A+B1. PTA Experiment Results

2. Design Ideas
    • 1. Define character array a[1001]={0},op[2]={0};, define array b[2]={0}; define variable i=0,sum=0,j=0,time=1,x=0;

    • 2. Enter a[i],while (a[i]!= ' \ n ', if the number is ' sum=sum*10+a[i]-' 0 '; ' If it is not a number and a space, then x=1; if (a[i]== ' &&time!=1,x=1;

    • 3. If (a[i]== ' &&time==1, if (x==1,op[j]= '? '); Otherwise if (sum<=0| | sum>1000), op[j]= '? ', otherwise b[j]=sum; j++;sum=0;time++;x=0

    • 4.i++, enter A[i], enter the next loop until you exit the loop.

    • 5. If (x==1,op[j]= '? '; Otherwise if (sum<=0| | sum>1000), op[j]= '? ', otherwise b[j]=sum;

    • 6. If op[0]== ' &&op[1]== ', Output ("%d +%d =%d", b[0],b[1],b[0]+b[1]);
      if (op[0]!= ' &&op[1]== '), the output ("? +%d =? ", B[1]),
      if (op[0]== ' \ &&op[1]!= '), output printf ("%d +?") =? ", b[0]);
      What if (op[0]!= ' &&op[1]!= ') output printf ("? + ? = ?");

3. Code


4. Problems encountered during commissioning and solutions
    • The problem encountered:

      • These are different from what you need
    • Solution: First add a judgment '. ', the '-' statement, in the value greater than 1000. and less than 1 is judged as '? '.

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

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

Lu Yong Treatment

2. My code, peer-to-peer code (the core code here is good, not necessarily all the code, the figure indicates whose code.) )
    • It's mine:

    • He's:

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.
    • I did two rounds of screening, and for the first time, all the characters except the beginning of the minus sign and the number are all out of the way, and the second time only began to evaluate, so my code is larger than his.

    • He is directly on the side to determine whether it is a number, one side of the calculation, and finally the minus sign directly to the last value by 1 on it.

In contrast, his code is relatively simple, and I am a step-by-step screening, because this can better clarify the idea, reduce the error rate. Of course I will also learn from Lu Yong and learn how he makes the code easier.

Iv. Study Summary of the Week 1. What did you learn? 1.1 How pointer variables are defined
int a,*p;char b,*q;p=&a;q=&b;
1.2 pointer addition operation in which case, can the 2 pointer variables be added to each other?
    • Can be used to change the pointer to the value of the element, or to change the position of the array;

    • cannot be added;

1.3 The pointer does not assign the initial value, direct use, what happens, please use DEVC verification, and show?

Using a pointer that is not initialized may cause the program to crash.

1.4 Lessons about separating the integer and fractional parts of floating-point numbers, use DEVC to verify the implementation, and show it in this map, and also indicate which is the pointer variable to do the function parameter, how is the function argument useful?

    • Formal parameter intpart,float fracpart

    • An argument is an address that allows it to be placed inside a custom function.

1.5 Please change the bubble sort function of the textbook into a pointer variable to do the formal parameter format, and write the code at the bottom, pay attention to the markdown syntax rendering.
void bubblde(int *p,int n){    int i,j,t;    for(i=1;i<=n;i++)         for(j=0;j<n-i;j++)            if(*(p+j)>*(p+j+1)){                t=*(p+j);                *(p+j)=*(p+j+1);                *(p+j+1)=t;            }}
1.6 How to define a pointer variable to an array, and how to use a pointer variable to represent an array element?
int *p,a[2];p=a;(p=&a[0];)
1.7 How do I define a character pointer to a string? Where is the initial position after the pointer points to the string?
char *p,op[]={ab}; p=op;

Initial position in Op[0]

1.8 Use a character pointer to manipulate strings, such as design functions, to implement string joins, and show the code in this map. What are the advantages of the method that indicates the pointer represents a character?

The values in the convenient array are from the main function to the custom function.

2. This week's content, you are not what? 2.1 Class allocation and how to revise the wrong questions.
    • The one I chose was to assign the value of a to the pointer directly without pointing to a variable. So it's wrong. It should be defined and pointed to, as *p=&a can

    • To understand the error, it should be first to judge the P1==&m is not established, is not set to 0; so 0;

2.2 Others not? How are we going to solve

Study what is wrong, and then learn the better code used in class.

3. Array on-Machine exam summary 3.1 The wrong question, please list?
    • 6-1 Array Loop Right shift

    • 6-2 jmu-c-Two-dimensional array transpose and sort by column

    • 7-1 IP Address Translation

    • 7-2 jmu-c-Decimal Turn 16 binary

    • 7-3 jmu-c-character string between output characters

    • 7-4 deletion of array elements

3.2 Wrong question How to revise, why wrong?
    • 6-1 Array Loop Right Shift: M>n is not considered, and when N and M more than 10 o'clock, the code display error, should not consider the situation, one by one, instead of a unified exchange, so that there is no such errors.

    • 6-2jmu-c-two-dimensional array transpose and sort by column; I will change the following, and the above does not change, resulting in errors; you should use a variable to hold the value below and change the value below to the value above, and then assign the value of the variable to it.

    • 7-1 IP Address Translation: The range is wrong, you should enter 32 numbers, and my last number is ' m '.

    • 7-2 jmu-c-Decimal Turn 16 binary: Directly output it, the last letter is a lowercase letter, should be used as a character array, when it is lowercase letters, automatically converted to uppercase letters;

    • 7-3 jmu-c-The character string between output characters: When the end character is also output before the start character, it should be determined where the ending character must be at the beginning of the word specifier.

    • 7-4 the deletion of the array elements: the original 10 digits after the deletion, the output is still 10 numbers, the following numbers are 8 and 10, without a for loop and instead of a while loop, and will delete a number each time, after moving in the count of the number of i+1 "";

C Language Blog Job--character 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.