十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
C語言中沒有吧?C++中倒是有一個:
站在用戶的角度思考問題,與客戶深入溝通,找到汕尾網(wǎng)站設(shè)計與汕尾網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站制作、做網(wǎng)站、外貿(mào)營銷網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名申請、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋汕尾地區(qū)。
next_permutation(array,array+arrlength)
使用的頭文件是#include algorithm
示例:
#include?iostream
#include?algorithm????///?next_permutation,?sort
using?namespace?std;
int?main?()?{
int?myints[]?=?{1,2,3,1};
sort?(myints,myints+4);
do?{
cout??myints[0]??'?'??myints[1]??'?'??myints[2]??'?'?myints[3]'\n';
}?while?(?next_permutation(myints,myints+4)?);????///獲取下一個較大字典序排列
cout??"After?loop:?"??myints[0]??'?'??myints[1]??'?'??myints[2]??'?'?myints[3]?'\n';
return?0;
}
一:全局變量
#include?stdio.h
int?a,b,c;??//定義三個全局變量
void?sort()??//不需要參數(shù)
{
int?t;
if(ab)
{
t=a;a=b;b=t;
}
if(bc)
{
t=b;b=c;c=t;
}
if(ab)
{
t=a;a=b;b=t;
}
}
int?main()
{
printf("輸入:");
scanf("%d%d%d",a,b,c);
sort();
printf("排序:%d??%d??%d\n",a,b,c);
return?0;
}
二:指針
#include?stdio.h
void?sort(int?*a,?int?*b,?int?*c)?//參數(shù)傳遞方式:地址傳遞
{?
int?t;
if(*a*b)?
{
t=*a;*a=*b;*b=t;
}
if(*b*c)
{
t=*b;*b=*c;*c=t;
}
if(*a*b)?
{
t=*a;*a=*b;*b=t;
}
}
int?main()
{
int?a,b,c;
printf("輸入:");
scanf("%d%d%d",a,b,c);
sort(a,b,c);???????????????//把地址作為參數(shù)
printf("排序:%d??%d??%d\n",a,b,c);
return?0;
}
#include stdio.h
#include string.h#define NUM 3
struct student
{
char name[20]; /*姓名*/
long num; /*12位學(xué)號*/
double sum; /*總分*/
};
void Create_Students(struct student stu[NUM])
{
struct student *p;
printf("請輸入學(xué)生姓名 學(xué)號(12位) 總分:\n");
for( p = stu; p stu+NUM; p++)
{
scanf("%s %d %lf",p-name,p-num,p-sum); }
}
void Order_Students(struct student stu[NUM])//起泡法
{
int i,j;
struct student temp;
for(i=NUM-1;i=0;i--)
for(j=0;ji;j++)
if(stu[j].sumstu[j+1].sum)
{
temp = stu[j];
stu[j] = stu[j+1];
stu[j+1]=temp;
}
}
void main()
{
int i=1;
struct student *p;
struct student stu[NUM];
Create_Students(stu);
Order_Students(stu);
printf("%-20s %-13s %-6s %4s\n","姓名","學(xué)號(12位)","總成績","名次");
for(p=stu;pstu+NUM;p++,i++)
{
printf("%-20s %-13.0d %-8.2f %2d\n",p-name,p-num,p-sum,i);
}
}//你參考參考,嘿
#include?stdio.h
void?func(int?*a)
{
int?i,j,temp;
for(j=0;j=7;j++)?
{?
for?(i=0;i7-j;i++)?
if?(a[i]a[i+1])?
{?
temp=a[i];?
a[i]=a[i+1];?
a[i+1]=temp;
}?
}?
}
int?main()
{
int?a[8]={8,7,6,5,4,3,2,1};
func(a);
for(int?i=0;i8;i++)
{
printf("%d?",a[i]);
}
return?0;
}
func就是功能函數(shù)實現(xiàn)數(shù)組a[8]的排序。