Code for the preparation of level two C language practice---Tutorial materials "C language Classic programming 282 cases"--(1)

Source: Internet
Author: User

Because of the second level of the use of the C language compiler is vc++6.0 really day of the dog with this compiler this is my 2nd C compiler bar, the first use is Ah ha C compiler: The second is vs++6.0 and then in the win under the VS2013 feel very good after all is a big development of software code completion, and format, font, you can also change the background of the code, a variety of functions, is to the novice, you use scanf it does not let you use, let you use scanf_s, Because it felt so safe, to avoid some of the xx overflow and so on, and get to write gets_s () and so on, I think if I have been using VS2013 that test when the code is written in this format ... I am sure VS6.0 will error, and then I have to find the wrong, this delay the test of valuable time! , so I decided to use vc++6.0 for the compiler of this book, feeling and using vim almost ... Just look at the code to complete this quick word ... Completed level two C.. I'm sure I'll be able to test!!!. (The drum can not be leaked) and then let vc++6.0 bye bye

November 29, 2015 04:52:00 code practice begins ~ ~ ~

13 numbers from small to large I still don't know how to sort the old halo probably understand I also back!
#include <stdio.h>2 intMain ()3 {4 inta,b,c,t;5printf"Please input a,b,c;\n");6scanf" %d%d%d",&a,&b,&c);7 8 if(a>b)9{//A B value is exchanged by TTent=A; OneA=b; Ab=T; - } - if(a>c) the{//A C value by the T interchange after a and B and C compared to a if the maximum value is placed on the last side -t=A; -A=C; -C=T; + } - + if(b>c) A{//b and C, then the maximum value is placed in the back . att=b; -b=C; -C=T; - } -printf"The order of the number is:\n"); -printf" %d%d%d", a,b,c); in return 0; -}

  

Monkeys eat peach.
#include <stdio.h>intMain () {intday,x1,x2; Day=9;//variables that record the number of daysX2=1;//number of Peaches on the 10th day while(day>0)//9 8 7 6 5 4 3 2 1{x1= (x2+1)*2;//1. Monkeys eat peach number +1 to get the original half of the number 2. Then X2 get the amount that was left of the peach the day before. The monkeys eat 1 and a half and then eat 1------>>>> We're going to have to go +1 to figure out how much he eats half. And then X2 get the amount it eats. I finally figured it out! X2=X1; Day--; } printf ("The total is %d\n", X1); return 0;}
/* I wrote it myself. printf is used to print the number of peach days and peaches but this code is not on it.

The number of peaches on the 9th day is 4
The number of peaches on the 8th day is 10
The number of peaches on the 7th day is 22
The number of peaches on the 6th day is 46
The number of peaches on the 5th day is 94
The number of peaches on the 4th day is 190
The number of peaches on the 3rd day is 382
The number of peaches on the 2nd day is 766
The number of peaches on the 1th day is 1534
Press any key to continue

*/

Tao Tao buys apples. Tao Tao to buy apples every day 0.8 yuan Tao Tao first day buy 2 the next day start buying twice times the previous one until the maximum number of apples purchased is not more than 100 <100
n is the number of variables per day (day++) n*2 x2 The number of apples purchased per day is 2 4 8 16 32 64 128 I added a program to output the number of apples in the Tao
#include <stdio.h>intMain () {intn=2, day=0;//number of first day and number of days floatmoney=0, Ave; while(n< -) { money=money+0.8*N; Day++; N*=2;//N each x2} Ave=money/Day ;
printf ("I'm a jerk, I buy apples every day.") I am Tao Tao I bought%d apples ", N/2);//Because n exits the loop because the n> or =100 is because the number of X is 2 so I have to/2 to get the amount of the Tao to buy apples printf ("The result is%.6f", Ave); return 0;} I'm a jerk. I buy apples every day. I'm Tao Tao, I bought 64 apples.//The result is 16.799999

Code for the preparation of level two C language practice---Tutorial materials "C language Classic programming 282 cases"--(1)

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.