当前位置:网站首页>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
边栏推荐
- 极限导论总结
- (JS) imitate an instanceof method
- [various * * question series] what are OLTP and OLAP?
- 如何通过WinDbg获取方法参数值
- Modbustcp protocol WiFi wireless learning single channel infrared module (round shell version)
- (JS) filter out keys with value greater than 2 in the object
- The last 48 hours! The cloud XR theme competition invites you to bloom together. See you at the competition!
- MySQL query table field information
- (JS) handwritten deep copy
- (JS)迭代器模式
猜你喜欢

【各种**问题系列】OLTP和OLAP是啥?

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

Online text filter less than specified length tool

9 款好用到爆的 JSON 处理工具,极大提高效率!

中国计算语言学大会、全国知识图谱与语义计算大会赛题火热进行中

Necessary for cloud native development: the first common codeless development platform IVX editor

Modbustcp protocol WiFi wireless learning single channel infrared module (round shell version)

Easydss is deployed on Disk C, and the video playback cannot be played normally. How to solve this problem?

Modbustcp protocol WiFi wireless learning single channel infrared module (small shell version)

Spark - Task 与 Partition 一一对应与参数详解
随机推荐
MySQL get table information
The Chinese Computational Linguistics Conference and the national knowledge atlas and Semantic Computing Conference are in full swing
(JS) array methods: slice and slice
What are the pop, push, unshift, and shift of the (JS) array?
TTL串口学习型红外遥控模块可扩展成网络控制
(JS) handwriting depth comparison
Online text filter less than specified length tool
(JS)职责链模式
Shell quotation marks and escape are rarely noticed, but they are often used in writing scripts
(JS) handwritten bind function
(JS)数组的 pop、push、unshift、shift分别是什么?
(JS) pure function in array
掌握一些shell 通配符巧妙的运用,会让我们写脚本事半功倍
多线程实现客户端与服务端通信(初级版本)
(JS)观察者模式
arcgis创建postgre企业级数据库
ruoyi框架中添加sharding sphere5.0.0分表(通过spi添加自定义分表策略)
Nuc980 open source project 16- start from SPI flash (w25q128)
ModbusTCP协议网络学习型单路红外模块(双层板)
BS-GX-017基于SSM实现的在线考试管理系统