C Language Blog Job-data type

Source: Internet
Author: User
Tags array definition

First, the PTA laboratory work Title 1:7-4 print Diamond Pattern 1. PTA Submission List

2. Design Ideas
{    int n,j,i,k;     输入n;    /*输出上半部分*/     for (i=1;i<=n;i=i+2) { 输出上半个菱形         for(j=n-i;j>0;j--)每一行输出的空格比上一行少两个            printf(" ");         for(k=i;k>0;k--)每一行输出的* 等于行数            printf("* ") ;        putchar(‘\n‘);换行     }     /*输出下半部分*/    for(i=n-2;i>0;i=i-2) {  下半部分与上半部分相反        for(j=n-i;j>0;j--) 输出的空格数            printf(" ");         for(k=i;k>0;k--)每一行输出的* 等于行数            printf("* ") ;        putchar(‘\n‘);换行    }    return 0;}
3. Code

4. Problems encountered in commissioning process and PTA submission List status note
    • Problems encountered: The output space when the condition is written (j=n-i+1;j>0;j--), resulting in a multiple output a space

    • Debugging process: Enter 3, after the output space

      Output

      After the line break, found and output a space, n=3, the second line should have no space

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

2. Design Ideas
{    定义变量分别存放原来的数以及计算后的数,定义count=1表示计算的次数    输入第一个数num1     储存num1,令num2=num1    调用trap函数,传入num1并将返还值存于num1     if(num1==num2)        输出printf("%d:%d",count,num1);     else{        while(num1!=num2){            储存num1的值,num2=num1;            调用函数num1=trap(num1);            输出printf("%d:%d",count,num1);             count++;         }         循环结束再输出一次 printf("%d:%d",count,num1);    }    结束 ;} int trap(int n)     计算陷阱数函数{    int x,sum=0;    while(x>0){        取出最低位x=n%10;        累加到 sum;        去掉最低位 x/=10;        }    sum = 3*sum+1;    
3. Code

4. Problems encountered in commissioning process and PTA submission List status note
    • Encountered the problem: At first did not store the value of the NUM1, called the function did not determine the num1==num2, resulting in the original should not enter the loop, only output the results, and enter the loop output once the results of the loop after the end of the output a result
    • Debugging process: Enter a value of 13

      After the function ends, the return value is 13, and the result should be output directly and then end the program, but the value before and after the return is not determined to be equal, resulting in a while loop

      Output a single result in a loop

      After the end of the loop output, a total output of two times, but to output once is enough

PTA List Description: The main situation is the above problem

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

2. Design Ideas
{    定义变量 int num,sum;    char op;    输入第一个数字num和第一个运算符op;    赋值sum=num;    while op!=‘=‘{         输入数字num;        if (op==‘/‘&&num==0)||(op!=‘+‘&&op!=‘-‘&&op!=‘*‘&&op!=‘/‘&&op!=‘=‘){    //如果运算符为‘/’同时输入数为0或者运算符不为‘+’,‘-’,‘*’,‘/’                输出Error;                结束 return 0;        }        else{            switch(op){        //判断运算符并进行相应运算                case ‘+‘:sum+=num;break;                case ‘-‘:sum-=num;break;                case ‘/‘:sum/=num;break;                case ‘*‘:sum*=num;break;                }            输入下一个运算符 op;        }    }    输出结果sum;    
3. Code

4. Problems encountered in commissioning process and PTA submission List status note
    • Problems encountered during the debugging process: (op== '/' &&num==0) conditions written (op= '/' &&num==0), the lack of an equal sign leads to a judgment condition error

    • PTA Submission List Description
      The commit list for PTA2 is because there is an equal sign in op== '/', 16 because there is no judgment on the denominator 0 and the illegal operator

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?

Definition: type name variable name [array length]
Initialization

    • The definition is initialized directly, such as: Int n[1]={0};
    • Implemented through a looping structure, such as:

      int n[10];for(i=0;i<10;i++){    scanf("%d",n[i]);}
1.2 A one-dimensional array in-memory structure? can draw a description. What does an array name mean?

1.3 Why use arrays?

Arrays are the same type of data uniformly compiled into a group, so that the array name + index number can be easily and quickly manipulate large amounts of data.

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

Selection method:

Bubbling method:

Direct Insert Sort:

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

Binary lookup: The intermediate element is compared to the lookup element, and if the lookup element is larger than the middle element, it is found on the right side of the middle element, and if the lookup element is smaller than the middle element, it is found on the left side of the middle element.
Difference from the sequential lookup method: Two-point lookup method for higher efficiency

1.6 How are two-dimensional arrays defined and initialized?

Two-dimensional array definition: type name variable name [line length] [column length]
Initialization

    • Branch Assignment Initial value:
      The general form is: type name variable name [line length] [column length]{{initial value table 0},... {Initial value Table k},...}
      For example: int a[2][3] = {{1,2,3},{4,5.6}}

    • The order is assigned the initial value:
      The general form is: type name variable name [line length] [column length]{initial table}
      For example: int [2][3]{1,2,3,4,5,6}

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.

Matrix transpose Process: the elements on the diagonal are not changed, the remaining elements are two subscript interchangeable, such as: n[0][1] transpose and become n[1][0]
Lower triangle: i>=j
Upper triangle: i<=j
Symmetric matrix: I=j

1.8 What is the general application of a two-dimensional array?

Applied when the array is in matrix form

2. This week's content, you are not what?
    • For the contents of this week's array, when defining a function, the arguments to the array are not very familiar
    • Bit operations for data types are also less likely to
    • The main problems and error points of PTA this week: 7-8 to judge the legal identifier: for the subject I was the first idea is to loop through a string of characters, distinguish between the initial character and each character, if an illegal character on the output of no, but in the process of the discovery of this output no, if the character has not been entered, The remaining characters will be treated as another new string, resulting in an incorrect answer, so change your mind to define a flag=0, loop through each character, and judge, the illegal character will be flag=1, the end of the loop and then by judging the value of flag output yes or No.

C Language Blog Job-data type

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.