The most typical 10 small programs in C language and small programs in C Language

Source: Internet
Author: User

The most typical 10 small programs in C language and small programs in C Language
[Procedure 1]

Question: How many three numbers can be composed of 1, 2, 3, and 4 numbers that are different from each other and have no repeated numbers? What is it?

1. Program Analysis: It can be filled in hundreds of digits, ten digits, and one digit is 1, 2, 3, and 4. Make up all sorts and then proceed

Drop the order that does not meet the conditions.

2. program source code:

Copy the Code as follows:

Main () {int I, j, k; printf ("\ n"); 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)/* Ensure that I, j, and k are different */printf ("% d, % d, % d \ n", I, j, k );}}

[Procedure 2]

Question: The bonus paid by an enterprise is based on the profit. If the profit (I) is less than or equal to 0.1 million yuan, the bonus can be raised by 10%. The profit is high.

If the price is less than 0.1 million yuan, the price of the part lower than 0.2 million yuan is 0.1 million, and the price of the part higher than 10% yuan is 0.1 million.

7.5%; 0.2 million to 0.4 million, more than 0.2 million yuan, can be raised to 5%; 0.4 million to 0.6 million is higher

For the part of 0.4 million yuan, it can be raised to 3%; for the part between 0.6 million and 1 million, the part above 0.6 million yuan can be raised to 1.5%, higher

1 million Yuan, more than 1 million yuan of part of the 1% commission, input the current month's profit from the keyboard I, the total number of bonuses payable?

1. Program Analysis: Use the number axis to divide and locate. Note that you need to define the bonus type as a growth integer.

2. program source code:

Copy the Code as follows:

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;elsebonus=bonus10+(i-1000000)*0.01;printf("bonus=%d",bonus);}

[Procedure 3]

Question: an integer. After 100 is added, it is a full number of workers, and 168 is a full number of workers. What is this number?

1. Program Analysis: If the value is less than 0.1 million, add 100 to the number before the start, and then add 268 to the number before the start. If

The following conditions are met. See the specific analysis:

2. program source code:

Copy the Code as follows:

# Include "math. h "main () {long int I, x, y, z; for (I = 1; I <100000; I ++) {x = sqrt (I + 100 ); /* x is the result after 100 is added. */y = sqrt (I + 268 ); /* y is the result after 168 is added. */if (x * x = I + 100 & y * y = I + 268) /* If the square of the square root of a number is equal to this number, it indicates that this number is a full number of bytes */printf ("\ n % ld \ n", I );}}

[Procedure 4]

Question: enter a day of a year to determine the day of the year?

1. Program Analysis: Taking January 1, March 5 as an example, we should add up the previous two months, and then add 5 days, that is, the day of the current year.

In this case, an additional day is required when the input month is greater than 3 in a leap year.

2. program source code:

Copy the Code as follows:

Main () {int day, month, year, sum, leap; printf ("\ nplease input year, month, day \ n"); scanf ("% d, % d, % d ", & year, & month, & day); switch (month)/* calculate the total number of days of the previous 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; default Rintf ("data error"); break;} sum = sum + day; /* plus the day of the day */if (year % 400 = 0 | (year % 4 = 0 & year % 100! = 0)/* determine whether it is a leap year */leap = 1; elseleap = 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 plus one day */sum ++; printf ("It is the % dth day. ", sum );}

[Procedure 5]

Question: input three integers x, y, and z. Please output these three numbers from small to large.

1. Program Analysis: we try to put the smallest number on x and compare x with y first. If x> y, the values of x and y are exchanged,

Then compare x with z. If x> z, the value of x is exchanged with z to minimize x.

2. program source code:

Copy the Code as follows:

Main () {int x, y, z, t; scanf ("% d", & x, & y, & z); if (x> y) /* swap the values of x and y */if (x> z)/* swap the values of x and z */if (y> z)/* swap z, y value */printf ("small to big: % d \ n", x, y, z );}

[Procedure 6]

Question: Use the letter "*" to output the C "pattern.

1. Program Analysis: You can first use the <|> * <|> Number to write the letter C on the paper, and then output it by branch.

2. program source code:

Copy the Code as follows:

#include "stdio.h"main(){printf("Hello C-world!\n");printf(" ****\n");printf(" *\n");printf(" * \n");printf(" ****\n");}

[Procedure 7]

Question: Output A special pattern. Run it in the c environment. Have a look, Very Beautiful!

1. Program Analysis: There are 256 characters in total. Different Characters and images are different.

2. program source code:

Copy the Code as follows:

#include "stdio.h"main(){char a=176,b=219;printf("%c%c%c%c%c\n",b,a,a,a,b);printf("%c%c%c%c%c\n",a,b,a,b,a);printf("%c%c%c%c%c\n",a,a,b,a,a);printf("%c%c%c%c%c\n",a,b,a,b,a);printf("%c%c%c%c%c\n",b,a,a,a,b); }

[Procedure 8]

Question: 9*9 tips.

1. Program Analysis: For branch and column consideration, there are 9 rows and 9 columns, I control row and j control column.

2. program source code:

Copy the Code as follows:

# Include "stdio. h "main () {int I, j, result; printf (" \ n "); for (I = 1; I <10; I ++) {for (j = 1; j <10; j ++) {result = I * j; printf ("% d * % d = %-3d", I, j, result);/*-3d indicates the left alignment, which occupies 3 places */} printf ("\ n");/* line feed after each line */}}

[Procedure 9]

Question: It is required to output the chess board.

1. Program Analysis: Use I control rows and j to control columns, and control the output black square or white square according to the sum of I + j.

2. program source code:

Copy the Code as follows:

#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);elseprintf(" ");printf("\n");}}

[Procedure 10]

Question: print the stairs and print two smiling faces above the stairs.

1. Program Analysis: Use I to control rows and j to control columns. j controls the number of black squares output based on I changes.

2. program source code:

Copy the Code as follows:

# Include "stdio. h "main () {int I, j; printf (" \ n ");/* output two smiling faces */for (I = 1; I <11; I ++) {for (j = 1; j <= I; j ++) printf ("% c", 219,219); printf ("\ n ");}}

 

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.