Programming Small class: 10 classic C Language Applet

Source: Internet
Author: User

Today to share 10 of the basic C language of the small program, I hope to give C language beginners to bring some help.

  

(It's home with map)

1, Title: There are 1, 2, 3, 4 digits, can make up how many different and no repetition of the number of three digits?

Program Analysis: Can be filled in hundreds, 10 digits, single digit numbers are 1, 2, 3, 4. Make all the permutations and then remove the permutations that do not meet the criteria.

Program Source code:

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)/* Make sure I, J, K three bits are different */

printf ("%d,%d,%d\n", i,j,k);

}

}

2, Title: The bonus awarded by the enterprise according to the profit commission. Profit (I) less than or equal to $100,000, the bonus can be raised 10%, the profit is higher than 100,000 yuan, less than 200,000 yuan, the portion of less than 100,000 yuan by 10% commission, higher than the portion of 100,000 yuan, Cocoa Commission 7.5%, 200,000 to 400,000, higher than 200,000 yuan of the portion, can commission 5%; Between 400,000 and 600,000 is higher than the portion of 400,000 yuan, can commission 3%, 600,000 to 1 million, higher than 600,000 yuan portion, can commission 1.5%, higher than 1 million yuan, the portion of more than 1 million yuan by 1% Commission, from the keyboard input month profit I, the total bonus should be issued?

Program Analysis: Please use the axis to demarcation, positioning. Note that the bonus definition should be defined as the growth integral type.

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);

}

3, Title: An integer, it plus 100 is a complete square number, plus 168 is a complete square number, what is the number?

Program analysis: In 100,000 to judge, the number plus 100 after the root, and then the number plus 268 after the root, if the result of the root satisfies the following conditions, that 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 radical. *

Y=SQRT (i+268); /*y is the result of adding 168 after the radical.

if (x*x==i+100&&y*y==i+268)/* If the square root of a number equals the square of the number, this indicates that the number is the total squared number */

printf ("\n%ld\n", I);

}

}

4, Title: Enter a year a certain day, judge this day is this year of the first day?

Program Analysis: Take March 5 as an example, should first add up the first two months, and then add 5 days that is the first day of the year, special cases, leap years and enter the month greater than 3 o'clock need to consider more than one day.

Program Source code:

Main ()

{

int day,month,year,sum,leap;

printf ("\nplease input year,month,day\n");

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

Switch (month)/* Calculates the total number of days of 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");

}

Sum=sum+day; /* Plus the days of the day * *

if (year%400==0| | (year%4==0&&year%100!=0)) /* judgment is not 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 one day */

sum++;

printf ("It's the%dth day.", sum); }

5, Title: Input three integer x, y, Z, please put these three numbers from small to large output.

Program Analysis: We try to put the smallest number on the X, first compare x with Y, if x>y the value of x and Y, and then compare X with Z, if x>z the value of X and Z, this will make x the smallest.

Program Source code:

Main ()

{

int x,y,z,t;

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

if (x>y)

/* Swap values for x, Y */

if (x>z)

/* Swap the value of x,z */

if (y>z)

/* Swap the value of Z,y */

printf ("Small to big:%d%d%d\n", X, Y, z);

}

6, Title: Use the * number output letter C pattern.

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

Program Source code:

#include "stdio.h"

Main ()

{

printf ("Hello c-world!\n");

printf ("****\n");

printf ("*\n");

printf ("* \ n");

printf ("****\n");

}

7, Title: Output Special pattern, please run in C environment, see, Very beautiful!

Program Analysis: A total of 256 characters. Different characters, graphics are not the same.

Program Source code:

#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); }

8, Title: Output 9*9 formula.

Program analysis: Branch and column considerations, a total of 9 rows of 9 columns, I control row, J control column.

Program Source code:

#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 = left-aligned, 3-bit */

}

printf ("\ n");/* Break line after each line */

}

}

9. Title: Requires the output of chess chessboard.

Program analysis: With I control line, J to control the column, according to the I+j and changes to control the output of black squares, or white squares.

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 ("\ n");

}

}

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

Program analysis: With I control line, J to control the column, J according to I change to control the number of output black squares.

Program Source code:

#include "stdio.h"

Main ()

{

int i,j;

printf ("\ n");/* Output two smiley faces */

for (i=1;i<11;i++)

{

for (j=1;j<=i;j++)

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

printf ("\ n");

}

}

Printing http://www.biyinjishi.com/
Printing Knowledge http://www.biyinjishi.com/kdocs/
Printing Tips http://www.biyinjishi.com/kdocslist/1/
Print Template http://www.biyinjishi.com/kdocslist/2/
Printing Process http://www.biyinjishi.com/kdocslist/3/
Printed material http://www.biyinjishi.com/kdocslist/4/
Print Creative http://www.biyinjishi.com/kdocslist/5/
Printing Platform http://www.biyinjishi.com/kdocslist/6/
Ordinary business card http://www.biyinjishi.com/products/a10-b1010/d100001/
mid-end business card http://www.biyinjishi.com/products/a10-b1010/d100002/
High-end business card http://www.biyinjishi.com/products/a10-b1010/d100003/
Creative Business Card http://www.biyinjishi.com/products/a10-b1010/d100004/
Membership card http://www.biyinjishi.com/products/a10-b1020/
PVC Membership Card http://www.biyinjishi.com/products/a10-b1020/d100006/
Magnetic stripe membership card http://www.biyinjishi.com/products/a10-b1020/d100007/
Chip membership card http://www.biyinjishi.com/products/a10-b1020/d100008/

Programming Small class: 10 classic C Language Applet

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.