C language The third time blog job---Single-layer loop structure

Source: Internet
Author: User
Tags pow

First, the PTA experimental work Title 1: The Best couple height difference 1. Experiment Code
  intN,i; Doubleheight; Height indicates statureCharsex; Sex represents gender (height>=1.0&&height<=3.0); (N>0&&n<=Ten); scanf ("%d",&N);  for(i=1; i<=n;i++) {scanf ("\N%C%LF",&sex,&height); if(sex=='F') {printf ("%.2f\n", height*1.09); }      Else{printf ("%.2f\n", height/1.09); }  }

2. Design Ideas
    • First step: Define integer variable n,i, double-precision floating-point variable height storage height, character type variable sex store sex, input n range 1.0<=hight<=3.0
    • Step Two: Enter the value of n
    • Step three: Enter Sex sex, enter height hight, variable initialize i =1
    • Fourth step: If the input sex is F, the value of hight*1.09 is output and two decimal places are left, otherwise the value of hight/1.09 is output and two decimal places are reserved. I plus one
    • Fifth step: Repeat step 3 until I >n
3. Problems encountered during commissioning and solutions
    • This wrote a variety of methods, for statements, while statements, switch statements but also the output answer equals 0.00, and later consulted the classmate to enter the place with a newline character, change to such scanf ("\n%c%lf", &sex,&height); The input m or F will not be absorbed by the space.
4. PTA Submission List

Topic 2: Special A-string series summation 1. Experimental code
 intA,n,i,s,item;//item is used to store each item, S is used to store the cumulative and(a,n>0&&a,n<=9); scanf ("%d%d",&a,&N); I=1; S=0; Item=0;  while(i<=N) {Item=item+a*pow (Ten, I-1); S=s+item; I++; } printf ("s =%d\n", s);

2. Design Ideas
    • The first step: Define the variable A,n,i,s,item,item for each entry, s for storing the accumulation and the range of the input a,n 0<a,n<=9
    • Step Two: variable initialization i =1;s=0;item=0 and enter the value of A,n
    • Step three: Item=item+a*pow (10,i-1);  S=s+item; i++;
    • Fourth step: Repeat step 3 until I >n
    • Fifth step: The value of the output s
3. Problems encountered during commissioning and solutions
    • There is not much problem at the beginning of the thinking when the introduction of the variable item, and then thought for a few minutes to think of the formula is correct.
4. PTA Submission List

Topic 3: Find the Minimum value 1. Experiment Code
  intn,i,number,min; Min is the minimum value (n>0); scanf ("%d",&N); scanf ("%d",&Number ); Min=Number ;  for(i=1; i<n;i++) {scanf ("%d",&Number ); if(number<min) min=Number ; } printf ("min =%d\n", Min);

2. Design Ideas
    • First step: Define integer variables I,n,number,min,n>0
    • Step Two: Enter the value of N, and the value of a number, and assign the value of number to min
    • The third step: Enter a number again, if the number>min, then the value is assigned to min,i++;
    • Fourth step: Repeat step 3 until I>=n
    • Fifth step: Output the value of Miin
3. Problems encountered during commissioning and solutions
    • Put the hint into the loop, the output of a number of enter marks: see with the problem output, the printf transferred out, and then devc++ on the PTA or the answer is wrong, and then think of the output format of the topic only min equals how much, all the output hints are deleted on the right.

4. PTA Submission List

Topic 4: Guessing number Games 1. Experiment Code
    intYournumber,mynumber,n,i,count; scanf ("%d%d",&mynumber,&N);  for(count=1; count<=n;count++) {scanf ("%d",&yournumber); if(yournumber<0) {printf ("Game over\n"); Break; }        Else if(yournumber>mynumber&&count<=n) printf ("Too big\n"); Else if(yournumber<mynumber&&count<=n) printf ("Too small\n"); Else if(yournumber==MyNumber) {            if(count==1) {printf ("bingo!\n");  Break; }            if(count==2|| count==3) {printf ("Lucky you!\n");  Break; }            if(count>3&&count<=N) {printf ("Good guess!\n");  Break; }        }    }    if(yournumber!=mynumber&&count>n) printf ("Game over");

2. Design Ideas
    • The first step: Define the variable mynumber,yournumber,i,n.
    • The second step: input variables MyNumber and n values, MyNumber represents the system randomly generated number, n control the number of cycles.
    • The third step: Enter the loop to determine the number of input and the system randomly generated number of the size, if the first guessed on the output too big, in the last three times guessed on the output lucky you!, in the specified number of times guessed on the output good guess!, if too large output too big, too small on the output too Small, output game over if the number of games exceeds or the input is out of range.
3. Problems encountered during commissioning and solutions
    • This question is really impressive, devc++ on the run is right, but changed several times submitted has been only one point, and then has been modified, finally asked the classmate later found, has not paid attention to the order of input, MyNumber and n input order exchange, should first MyNumber again n. When the i>n output game over is also in the loop, but even in the loop is also running correctly, and finally I put the output statement outside the loop.

4. PTA Submission List

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

PTA Rankings

Submit List

Iii. Summary of this week's study 1. What have you learned?
    • Learned the For Statement loop, in numerator the simplest fraction that the problem broke the inertial thinking (inertia only use i=1;i<=n;i++). Learn the character type variable input, pay attention to the carriage return and space, enter the space is also counted characters, otherwise the characters that need to be entered will be replaced by a space or a carriage return.
    • The break end loop is used in the right place.
    • Learned to use the devc++ for simple debugging, according to the input data changes to find out where the error.
2. This week's content, you are not what?
    • More complex topic wrong or debugging comparison do not understand, their own ideas are difficult to clarify
    • Do-while statements are rarely used, and may be less judgmental, so often using the while or for statements
    • For no input of the topic, like the Han Xin soldiers of problem, it will feel very difficult, but this example I think more do will understand.
3. Branching structure on-machine examination summary. (1) Which place is wrong, why?
    • That output time, the beginning of the 12 points also minus 12, and then add pm, because I see the topic that the Noon 12 point unit is PM, put it with the afternoon time together, resulting in a wrong answer
(2) How to find the next procedure error?
    • Because of the time is not enough I ask classmates, follow-up I want to use a bit more debugging, see which step out of the problem, in the modification, more practice debugging
(3) Are you satisfied with your achievements? How do you improve your dissatisfaction?

Not satisfied. debugging or not, do not know where the breakpoint is better, and sometimes just look at it, and then I feel where the wrong to change, and playing code too slow, are a waste of time. Ask classmates, and often use debugging to find errors, and then type practice practice.

Good text to the top concern me to collect the article

C language The third time blog job---Single-layer loop structure

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.