当前位置:网站首页>The use of Fibonacci sequence and bubble sort in C language
The use of Fibonacci sequence and bubble sort in C language
2022-06-29 11:19:00 【Xiaohao programming】
One 、 Fibonacci series
First of all, let's briefly introduce what Fibonacci sequence is 
C See the following code for the language implementation logic
#include <stdio.h>
int main()
{
int arr[30] = {
0};
int i;
int arraysize;
arr[0] = 0;
arr[1] = 1;
arraysize = sizeof(arr)/sizeof(arr[0]);// Find out how many data there are in the array , In fact, that is 30 individual
for(i=2;i<arraysize;i++)
{
arr[i] = arr[i-1]+arr[i-2];
}
for(i=0;i<arraysize;i++)
{
printf("%d\n",arr[i]);
}
return 0;
}
Output the printed content as follows
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
Two 、 bubble sort
The following is a ranking of the largest to the smallest
#include <stdio.h>
int main()
{
int array[] = {
1,3,4,5,2};
int i;
int j;
int tmp;
int len = sizeof(array)/sizeof(array[0]);// Calculate how many pieces of data there are in the array , Here is 5, The purpose of this is , The data to be sorted can be changed in real time
for(i=0;i<len-1;i++)// Two for The purpose of the loop is to pick out the largest number , To compare the smaller
{
for(j=0;j<len-1-i;j++)
{
if(array[j] < array[j+1])// From small to large, change the less than sign to the greater than sign
{
tmp = array[j];
array[j] = array[j+1];
array[j+1] = tmp;
}
}
}
for(i=0;i<len;i++)
{
printf("%d\n",array[i]);// Printout
}
return 0;
}
Output results
5
4
3
2
1
边栏推荐
- 5. migrate uboot set default environment variables, crop, and partition
- What are the pop, push, unshift, and shift of the (JS) array?
- 数据分析方法与思维:漏斗分析
- ModbusTCP协议网络学习型单路红外模块(双层板)
- Modbustcp protocol WiFi wireless learning single channel infrared module (small shell version)
- Easydss is deployed on Disk C, and the video playback cannot be played normally. How to solve this problem?
- (JS)筛选出对象中value大于2的key
- [3 questions per day (2)] minimum operand for generating alternate binary strings
- LVGL库入门教程 - 动画
- nuc980 已成功启动
猜你喜欢

Interview questions of Tencent automation software test of CSDN salary increase secret script (including answers)

ModbusTCP协议WIFI无线学习型单路红外模块(小壳版)

(JS)筛选出对象中value大于2的key

misc3~7

Multithreaded high concurrency server: three problems

Week 12 experiment -- implementation of VGA protocol based on FPGA

Today in history: musk was born; Microsoft launches office 365; The inventor of Chua's circuit was born

在日本的 IT 公司工作是怎样一番体验?

Limit introduction summary

Google Earth Engine(GEE)——GEDI L2A Vector Canopy Top Height (Version 2) 全球生态系统数据集
随机推荐
[various * * question series] what are OLTP and OLAP?
【每日3题(1)】判断国际象棋棋盘中一个格子的颜色
(JS) imitate an instanceof method
(JS)数组去除重复
Necessary for cloud native development: the first common codeless development platform IVX editor
map合并相同的键,值合并为列表
When a technician becomes a CEO, what "bugs" should be modified?
(JS)手写深比较
VI exit exit VIM applicable novice
BS-GX-018 基于SSM实现在校学生考试系统
在编写shell脚本时如何正确姿势地管理临时文件
【每日3题(3)】重新格式化电话号码
Spark - Task 与 Partition 一一对应与参数详解
Specific method and example program of Siemens s7-200smart control stepping motor
(JS) observer mode
斐波那锲数列与冒泡排序法在C语言中的用法
MySQL get table information
Memory allocation - static storage stack heap and static variable
Multi thread communication between client and server (primary version)
MySQL 索引失效的几种类型以及解决方式