c language classic applet summary Daquan

There are a lot of people on the Internet who say how boring programming is. In fact: don't care what others say, what others say, do what you like to do. Stick to it and you will find programming fun. Of course, if you feel that learning a programming language is painful and persists for a period of time without fruit, it is not necessarily a good choice for South to give up.

10 classic C language applets, today I share 10 basic C-language programs, with a few commonly used 10 small examples, I hope to bring some help to C language beginners, skilled use, and give inferences.

c language classic applet summary Daquan

[Program 1]

Topic: There are 1, 2, 3, and 4 digits. How many three digits can be formed that are different from each other and have no duplicate numbers? What is it?

1. Program analysis: The numbers that can be filled in hundreds, ten, and ones are 1, 2, 3, and 4. After making all the arrangements, go

Drop the arrangement that does not satisfy the condition.

2. Program source code:

Main()

{

Int i,j,k;

Printf("");

For(i=1;i"5;i++) /*The following is a triple loop*/

For(j=1;j"5;j++)

For (k=1;k"5;k++)

{

If (i!=k&&i!=j&&j!=k) /* Make sure that i, j, and k are different from each other*/

Printf("%d,%d,%d",i,j,k);

}

}

[Procedure 2]

Topic: Enter a certain day of the month, and judge this day is the first day of the year?

1. Program analysis: Take March 5 as an example, you should add up the first two months, then add 5 days, the day of the year, special

In the case of a leap year and the input month is greater than 3, you need to consider adding one more day.

2. Program source code:

Main()

{

Int day,month,year,sum,leap;

Printf("please input year,month,day");

Scanf("%d,%d,%d",&year,&month,&day);

Switch(month)/*First calculate the total number of days in the month before month*/

{

Case 1:sum=0;break;

Case 2:sum=31;break;

Case 3:sum=59;break;

Case 4:sum=90;break;

Case 5:sum=120;break;

Case 6:sum=151;break;

Case 7:sum=181;break;

Case 8:sum=212;break;

Case 9:sum=243;break;

Case 10:sum=273;break;

Case 11:sum=304;break;

Case 12:sum=334;break;

Defaultrintf("data error");break;

}

Sum=sum+day; /* plus the number of days in a day*/

If(year%400==0||(year%4==0&&year%100!=0))/*Determine whether it is a leap year*/

Leap=1;

Else

Leap=0;

If(leap==1&&month 2)/* If it is a leap year and the month is greater than 2, the total number of days should be increased by one day*/

Sum++;

Printf("It is the %dth day.",sum); }

[Program 3]

Title: Enter three integers x, y, z, please output these three numbers from small to large.

1. Program analysis: We want to find the smallest number on x, first compare x with y, if x "y" exchange x and y values,

Then compare x with z, if x "z then exchange the values ​​of x and z, which will minimize x.

2. Program source code:

Main()

{

Int x,y,z,t;

Scanf("%d%d%d",&x,&y,&z);

If (x y)

/* exchange x, y value * /

If(x》z)

/* exchange x, z value * /

If(y)z)

/* exchanges the value of z,y*/

Printf("small to big: %d %d %d",x,y,z);

}

[Program 4]

Topic: Use the * to output the pattern of the letter C.

1. Program analysis: You can use the "|" * "|" number to write the letter C on the paper, and then output it in separate lines.

2. Program source code:

#include "stdio.h"

Main()

{

Printf("Hello C-world!");

Printf(" ****");

Printf(" *");

Printf(" * ");

Printf(" ****");

}

[Procedure 5]

Topic: Output special patterns, please run in c environment, take a look, Very Beautiful!

1. Program analysis: There are 256 characters. Different characters, graphics are different.

2. Program source code:

#include "stdio.h"

Main()

{

Char a=176, b=219;

Printf("%c%c%c%c%c",b,a,a,a,b);

Printf("%c%c%c%c%c", a, b, a, b, a);

Printf("%c%c%c%c%c", a, a, b, a, a);

Printf("%c%c%c%c%c", a, b, a, b, a);

Printf("%c%c%c%c%c",b,a,a,a,b); }

[Procedure 6]

Title: Output 9*9 port.

1. Program analysis: branch and column considerations, a total of 9 rows and 9 columns, i control row, j control column.

2. Program source code:

#include "stdio.h"

Main()

{

Int i,j,result;

Printf("");

For (i=1;i"10;i++)

{ for(j=1;j"10;j++)

{

Result=i*j;

Printf("%d*%d=%-3d",i,j,result); /*-3d means left aligned, 3 digits*/

}

Printf(""); /* wrap after each line */

}

}

[Procedure 7]

Title: Requires the output of a chess board.

1. Program analysis: use i to control the line, j to control the column, according to the change of the sum of i + j to control the output of the black square, or white square.

2. Program source code:

#include "stdio.h"

Main()

{

Int i,j;

For(i=0;i"8;i++)

{

For(j=0;j"8;j++)

If((i+j)%2==0)

Printf("%c%c",219,219);

Else

Printf(" ”);

Printf("");

}

}

[Procedure 8]

Title: Print the stairs while printing two smiley faces above the stairs.

1. Program analysis: use i to control the line, j to control the column, j to control the number of black squares output according to the change of i.

2. Program source code:

#include "stdio.h"

Main()

{

Int i,j;

Printf("");/* output two smiles*/

For(i=1;i"11;i++)

{

For(j=1;j"=i;j++)

Printf("%c%c",219,219);

Printf("");

}

}

[Program 9]

Title: The bonuses issued by enterprises are based on profit. When the profit (I) is lower than or equal to 100,000 yuan, the bonus can be increased by 10%; if the profit is higher than 100,000 yuan, if it is less than 200,000 yuan, the part below 100,000 yuan will be 10%, higher than 100,000 yuan. The portion of cocoa is 7.5%; between 200,000 and 400,000, the portion higher than 200,000 yuan can be made 5%; the portion between 400,000 and 600,000 is higher than 400,000 yuan, which can be 3%. When there is between 600,000 and 1 million, the part higher than 600,000 yuan can be 1.5%. When it is higher than 1 million yuan, the part exceeding 1 million yuan is made up of 1%, and the profit of the month is input from the keyboard. What is the total amount of bonuses issued?

Program analysis: Please use the number axis to demarcate and locate. Pay attention to the definition of the bonus to grow the integer.

Program source code:

Main()

{

Long int i;

Int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;

Scanf("%ld",&i);

Bonus1=100000*0.1;bonus2=bonus1+100000*0.75;

Bonus4=bonus2+200000*0.5;

Bonus6=bonus4+200000*0.3;

Bonus10=bonus6+400000*0.15;

If(i"=100000)

Bonus=i*0.1;

Else if(i"=200000)

Bonus=bonus1+(i-100000)*0.075;

Else if(i"=400000)

Bonus=bonus2+(i-200000)*0.05;

Else if(i"=600000)

Bonus=bonus4+(i-400000)*0.03;

Else if(i"=1000000)

Bonus=bonus6+(i-600000)*0.015;

Else

Bonus=bonus10+(i-1000000)*0.01;

Printf("bonus=%d",bonus);

}

[Program 10]

Title: An integer, which is a perfect square after adding 100, plus 168 is a perfect square number. What is the number?

Program analysis: judge within 100,000, first add 100 to the number and then open the square, then add 268 to the number and then open the square. If the result after the square meets the following conditions, the result is the result.

Program source code:

#include "math.h"

Main()

{

Long int i,x,y,z;

For (i=1;i"100000;i++)

{ x=sqrt(i+100); /*x is the result of adding 100 after the square root */

y=sqrt(i+268); /*y is the result of adding 168 after the square root*/

If(x*x==i+100&&y*y==i+268)/* If the square root of a number is equal to the number, this indicates that the number is a perfect square */

Printf("%ld",i);

}

}

Lens Hood Silicone Rubber Plugs

Nantong Boxin Electronic Technology Co., Ltd. , https://www.ntbosen.com