当前位置:网站首页>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
边栏推荐
- MySQL installation tutorial (detailed, package teaching package~)
- 力扣每日一题-第46天-704. 二分查找
- Centos 7.9安装PostgreSQL14.4步骤
- prometheus 监控概述
- 【Map与Set】之LeetCode&牛客练习
- uniapp uses 3rd party fonts
- 221. 最大正方形
- 蛮力法/邻接表 广度优先 有向带权图 无向带权图
- Likou Daily Question - Day 46 - 704. Binary Search
- After reading "MySQL Database Advanced Practice" (SQL Xiao Xuzhu)
猜你喜欢

934. The Shortest Bridge

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

ROS Action communication

内网渗透——提权

JPEG Steganalysis of Digital Image Steganography

221. 最大正方形

I have been working in software testing for 3 years, how did I go from just getting started to automated testing?

Word 表格跨页,仍然显示标题

What have I experienced when I won the offer of BAT and TMD technical experts?

Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化
随机推荐
Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"
How to expose Prometheus metrics in go programs
黄东旭:TiDB的优势是什么?
android的webview缓存相关知识收集
Overview of prometheus monitoring
The difference between 4G communication module CAT1 and CAT4
GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
《MySQL数据库进阶实战》读后感(SQL 小虚竹)
Distributed. Distributed lock
数字图像隐写术之JPEG 隐写分析
Installation problem corresponding to tensorflow and GPU version
221. 最大正方形
ROS Action通信
力扣每日一题-第46天-704. 二分查找
来自一位女测试工程师的内心独白...
The Meta Metaverse Division lost 2.8 billion in the second quarter, still want to continue to bet?Metaverse development has yet to see a way out
coldfusion文件读取漏洞(CVE-2010-2861)
Interprocess communication study notes
leetcode-952: Calculate max component size by common factor
什么是理想的大学生活?