当前位置:网站首页>C language applet -- common classic practice questions
C language applet -- common classic practice questions
2022-07-31 01:46:00 【south wind fahaxiki】
Share 5 simple C language small programs, now you, do you still remember the C language you studied hard at the time, the classic C language questions, recall it
[Program 1] Question: With 1, 2, 3, and 4 numbers, how many different three-digit numbers can be formed without repeating numbers?How much are they?
1. Program analysis: The numbers that can be filled in the hundreds, tens, and ones are 1, 2, 3, and 4.Make up all the permutations and then remove the permutations that do not meet the conditions.
2. Program source code:
#include int 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 are different from each other*/printf("%d,%d,%d\n",i,j,k);}} 【Program 2】
Question: Enter a certain day, a certain month, a certain year, and determine the day of the year?
1. Program analysis: Take March 5th as an example, you should add up the first two months, and then add 5 days, which is the first day of the year, special cases, leap years and the input month is greater than 3need to consider an extra day.
2. Program source code:
#include int main(){int day,month,year,sum,leap;printf("\nplease input year,month,day\n");scanf("%d,%d,%d",&year,&month,&day);switch(month) /*First calculate the total number of days in the month before a certain 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:printf("data error");break;}sum=sum+day; /*Add 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;elseleap=0;if(leap==1&&month>2) /*If it is a leap year and the month is greater than 2, add one day to the total number of days*/sum++;printf("It is the %dth day.",sum);} 【Program 3】
Title: Input three integers x, y, z, please output the three numbers from small to large.
1. Program analysis: We find a way to put the smallest number on x, first compare x with y, if x>y, exchange the values of x and y, and then compare x and z, if x>z, swap the values of x and z to minimize x.
2. Program source code:
#include int main(){int x,y,z,t;scanf("%d%d%d",&x,&y,&z);if (x>y){t=x;x=y;y=t;} /*Swap the values of x,y*/if(x>z){t=z;z=x;x=t;} /*Swap the values of x,z*/if(y>z){t=y;y=z;z=t;} /*Swap the values of z,y*/printf("small to big: %d %d %d\n",x,y,z);} 【Program 4】
Title: Output 9*9 formula.
1. Program analysis: consider row and column, a total of 9 rows and 9 columns, i controls the row, j controls the column.
2. Program source code:
#include int main(){int i,j,result;printf("\n");for (i=1;i<10;i++){for(j=1;j 【Program 5】
Title: Print out all the "daffodils number", the so-called "daffodil number" refers to a three-digit number, and the sum of the cubes of the digits is equal to the number itself.For example: 153 is a "daffodil number", because 153=1 cube + 5 cube + 3 cube.
1. Program analysis: use the for loop to control 100-999 numbers, each number is decomposed into units, tens, and hundreds.
2. Program source code:
#include main(){int i,j,k,n;printf("'water flower'number is:");for(n=100;n<1000;n++){i=n/100;/*Decompose to the hundreds place*/j=n/10%10;/*decompose to ten digits*/k=n%10;/*Decompose out the one digit*/if(i*100+j*10+k==i*i*i+j*j*j+k*k*k)printf("%-5d",n);}} And that's it for today, everyone remember to like and favorite, share and forward, and pay attention to little brother!Finally, if you want to learn or are learning C/C++ programming, you can join Editor’s Programming Learning C/C++ Penguin Circle
边栏推荐
- uniapp uses 3rd party fonts
- 两个有序数组间相加和的Topk问题
- Crawler text data cleaning
- SQLserver查询最近三个月的数据,语句该怎么写sqlserver
- 爬虫文本数据清洗
- JPEG Steganalysis of Digital Image Steganography
- Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"
- 221. 最大正方形
- 手把手教你配置Jenkins自动化邮件通知
- MySql installation and configuration super detailed tutorial and simple method of building database and table
猜你喜欢

【flask入门系列】Flask-SQLAlchemy的使用

GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13

Nacos

The sword refers to offer17---print the n digits from 1 to the largest

《云原生的本手、妙手和俗手》——2022全国新高考I卷作文

16、注册中心-consul

软件测试基础接口测试-入门Jmeter,你要注意这些事

Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"

Ticmp - 更快的让应用从 MySQL 迁移到 TiDB

一个无经验的大学毕业生,可以转行做软件测试吗?我的真实案例
随机推荐
coldfusion8后台计划任务拿shell
C language _ structure pointer array function voting system
CV-Model [3]: MobileNet v2
来自一位女测试工程师的内心独白...
MySQL的存储过程
内网渗透——提权
成为比开发硬气的测试人,我都经历了什么?
手把手教你配置Jenkins自动化邮件通知
【AcWing 62nd Weekly Game】
Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"
Teach you how to configure Jenkins automated email notifications
The difference between 4G communication module CAT1 and CAT4
蛮力法/邻接矩阵 广度优先 有向带权图 无向带权图
Multiplication, DFS order
Arbitrum Interview | L2 Summer, what does the standout Arbitrum bring to developers?
SQLserver查询最近三个月的数据,语句该怎么写sqlserver
uniapp uses 3rd party fonts
keep-alive cache component
数字图像隐写术之卡方分布
软件测试缺陷报告---定义,组成,缺陷的生命周期,缺陷跟踪产后处理流程,缺陷跟踪处理流程,缺陷跟踪的目的,缺陷管理工具