编写一个函数,把double类型数组中的数据倒序排列,并在一个简单的程序中测试该函数

编写一个函数,把double类型数组中的数据倒序排列,并在一个简单的程序中测试该函数,第1张

C语言程序:

#include <stdio.h>

//冒泡排序

void sort(double arr[], int n)

{

int i, j

double temp

for(i=0 i<n-1 i++)

for(j=0 j<n-1-i j++)

if(arr[j] < arr[j+1])

{

temp = arr[j]

arr[j] = arr[j+1]

arr[j+1] = temp

}

}

//输出数组元素

void display(double arr[], int n)

{

int i

for(i=0 i<n i++)

printf("%lf  ", arr[i])

printf("\n")

}

//主函数

int main()

{

double arr[] = {49.5, 38.2, 65.1, 97.0, 76.8, 13.4, 27.9, 49.5}

int n = 8

printf("排序前:\n")

display(arr, n)

sort(arr, n)

printf("排序后:\n")

display(arr, n)

return 0

}

运行测试:

create or replace function F_STR_CG(str in varchar2) return varchar2 is

Result varchar2(5000)

str_len int

i int

str1varchar2(5000)

str2varchar2(5000)

begin

select length(str) into str_len from dual

str1 := str

for i in 1 .. str_len loop

select substr(str1, -1) into str2 from dual

result := result || str2

select substr(str1, 1, str_len - i) into str1 from dual

end loop

return(result)

end F_STR_CG

Oracle数据库的,你可以参考一下

一:SQL 2000

select top 10 from table

order by GID

desc --倒序(asc --是顺序

二:oracle

select * from table

where rownum<11

order by GID

desc --倒序(asc --是顺序)

rownum是oralce 的SQL中内置的一个函数,它的作用是:限制返回记录条数


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6770889.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-28
下一篇 2023-03-28

发表评论

登录后才能评论

评论列表(0条)

保存