當前位置:首頁 » 操作系統 » c源碼

c源碼

發布時間: 2022-01-12 13:22:04

1. 請求c代碼

以下程序在 Borland C++ Builder 中測試通過

/////////////////////////////////

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

void tc(char **a,int n,int maxlen) ;
void pp(char **,int,int);
int main(int argc, char* argv[])
{ int n,i,len=0,ml=0;
char **c=NULL,t[80];
scanf("%d",&n);
c=realloc(c,n*sizeof(char *));
assert(c!=NULL);
for (i = 0; i<n; i++)
{
scanf("%s",t);
c[i]=malloc(strlen(t)*sizeof(char));
assert(c[i]!=NULL);
strcpy(c[i],t);
len+=strlen(c[i]);
ml=(ml<(int)strlen(c[i]))?strlen(c[i]):ml;
}

tc(c,n,ml);
pp(c,n-1,0);

system("pause");
return 0;
}

void pp(char **a,int n,int sl)
{
int i,p,o;
char *b;
for (i = 0; i<=n-1; i++)
{
o=i;
for (p=i+1; p<=n; p++)
if (strcmp(a[o],a[p])<0) o=p ;
if (o!=i)
{

b=a[o];
a[o]=a[i];
a[i]=b;
}
}
for (i=0; i<=n; i++)
{
for (p=0; p<(int)strlen(a[i]); p++)
{
if (a[i][p]=='a')
{
a[i][p]='\0';
break;
}
}
printf("%s",a[i]);
}
putchar('\n');
}

void tc(char **a,int n,int maxlen)
{
int i,p;
for (i=0; i<n; i++)

if ((int)strlen(a[i])<maxlen)

for (p=strlen(a[i])-1; p<maxlen; p++)

strcat(a[i],"a");
}

///////////////////////////////////////////

程序已修改。

2. 怎樣用Microsoft visual c++把c源代碼編譯成exe 可執行文件

以VC6舉例:

1、打開電腦上安裝的vc6.0,進入如圖界面

3. 二元一次方程 的c源碼

float a,b,c,disc,x1,x2,p,q;
scanf("%f%f%f",&a,&b,&c);
disc=b*b-4*a*c;
if(disc<0)printf("error");
else
{
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p-q;
x2=p+q;
printf("x1=%.2f\nx2=%.2f\n",x1,x2);
}}}}
試試~看看是不是你想要的

4. 找中值的c語言源代碼

#include<iostream>
#include<cstdlib>
#include<ctime>
#include<algorithm>

usingnamespacestd;


voidswap(intA[],inti,intj)
{
if(i!=j)
{
intt=A[i];
A[i]=A[j];
A[j]=t;
}
}

intpartition(intA[],intp,intr)
{
intx=A[r];
inti=p-1;
for(intj=p;j<=r-1;j++)
{
if(A[j]<=x)
{
i++;
swap(A,i,j);
}
}
swap(A,i+1,r);
returni+1;
}

intrandomized_partition(intA[],intp,intr)
{
srand(time(NULL));
inti=p+rand()%(r-p+1);
swap(A,i,r);
returnpartition(A,p,r);
}

intrandomized_select(intA[],intp,intr,inti)
{
if(p==r)returnA[p];
intq=randomized_partition(A,p,r);
intk=q-p+1;

if(i==k)returnA[q];
elseif(i<k)returnrandomized_select(A,p,q-1,i);
elsereturnrandomized_select(A,q+1,r,i-k);
}

voidtriplet_adjust(intA[],inti,intstep)
{
intj=i+step;
intk=i+2*step;
if(A[i]<A[j])
{
if(A[k]<A[i])swap(A,i,j);
elseif(A[k]<A[j])swap(A,j,k);
}
else
{
if(A[i]<A[k])swap(A,i,j);
elseif(A[k]>A[j])swap(A,j,k);
}
}

doublemean(intA[],intn)
{
doublef=A[0];
for(inti=1;i<n;i++)f+=A[i];
returnf/n;
}

intapproximate_median(intA[],intr)
{
intstep=1;
intsize=1;
inti;
for(intj=0;j<r;j++)size*=3;
for(intk=0;k<r;k++)
{
i=(step-1)/2;
while(i<size)
{
triplet_adjust(A,i,step);
i+=(3*step);
}
step*=3;
}
returnA[(size-1)/2];
}

voidselection_sort(intA[],intleft,intsize,intstep)
{
intmin;
inti,j;
for(i=left;i<left+(size-1)*step;i+=step)
{
min=i;
for(j=i+step;j<left+size;j+=step)
{
if(A[j]<A[min])min=j;
}
swap(A,i,j);
}
}

template<classT,classS>
voidncmerge_sort(T*_A,S_N)
{
Sstep,ins,l,m,r,pos0,pos1;
T*_T=newT[_N];

for(step=2;step<_N*2;step*=2)
{
for(l=0;l+step/2<_N;l+=step)
{
m=l+step/2;
r=m+step/2<_N?m+step/2:_N;
pos0=l;pos1=m;ins=0;
while(pos0<m&&pos1<r)
{
if(_A[pos1]<_A[pos0])_T[ins++]=_A[pos1++];
else_T[ins++]=_A[pos0++];
}
while(pos0<m)_T[ins++]=_A[pos0++];
while(pos1<r)_T[ins++]=_A[pos1++];
while(ins>0)_A[--r]=_T[--ins];
}
}
delete[]_T;
}
constintSORT_NUM_THRESHOD=50;

intapproximate_median_any_n(intA[],intsize)
{
boolleft_to_right=false;
intleft=0;
intstep=1;
inti;
while(size>SORT_NUM_THRESHOD)
{
left_to_right=!left_to_right;
intrem=size%3;
if(left_to_right)i=left;
elsei=left+(3+rem)*step;
for(intj=0;j<(size/3-1);j++)
{
triplet_adjust(A,i,step);
i+=3*step;
}
if(left_to_right)left+=step;
else
{
i=left;
left+=(1+rem)*step;
}
selection_sort(A,i,3+rem,step);
if(rem==2)
{
if(left_to_right)swap(A,i+step,i+2*step);
elseswap(A,i+2*step,i+3*step);
}
step*=3;
size=size/3;
}
selection_sort(A,left,size,step);
returnA[left+step*int((size-1)/2)];
}

intmain(intargc,char*argv[])
{
constintDEFAULT_N=50000000;
intN;
if(argc<2)
{
N=DEFAULT_N;
}
else
{
N=atoi(argv[1]);
}
cout<<"N="<<N<<endl;
clock_tt=clock();
cout<<clock()<<endl;
int*A=newint[N];
cout<<clock()<<endl;
srand(time(NULL));
for(inti=0;i<N;i++)
{
A[i]=rand()%N;
}

clock_tt1=clock();
cout<<t1<<endl;
doubleavg=mean(A,N);
cout<<avg<<endl;
clock_tt2=clock();
cout<<t2<<endl;
intm=approximate_median_any_n(A,N);//近似中值選擇演算法,不太精確,但速度快點
cout<<m<<endl;
clock_tt3=clock();
cout<<t3<<endl;
m=randomized_select(A,0,N-1,N/2);//隨機選擇法
cout<<m<<endl;
clock_tt4=clock();
cout<<t4<<endl;
//std::sort(A,A+N);//標准快速排序
ncmerge_sort(A,N);//原地並歸排序,排序法
m=A[N/2];
cout<<m<<endl;
clock_tt5=clock();
cout<<t5<<endl;
cout<<endl;
doubledt=(double)(t2-t1)/CLOCKS_PER_SEC;
cout<<dt<<"";
dt=(double)(t3-t2)/CLOCKS_PER_SEC;
cout<<dt<<"";
dt=(double)(t4-t3)/CLOCKS_PER_SEC;
cout<<dt<<"";
dt=(double)(t5-t4)/CLOCKS_PER_SEC;
cout<<dt<<"";
cout<<endl;

return0;
}

5. C語言源代碼是什麼

數字版「拼圖」游戲C源代碼:

#include<time.h>

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

#include<windows.h>

int i, j, r, k; //i、j、r用於循環, k存放隨機數值


int m, n; // m、n是當前空位的下標, t標記排序是否成功

int a[4][4]; //存儲4×4共16個數字的數組

void show(void); //輸出數組表格

void csh(void); //初始化界面

int yes(void); //判斷排序是否成功

void up(void); //數字向上移動到空位(空位則下移)

void down(void); //數字向下移

void left(void); //數字向左移

void rght(void); //數字向右移

void inkey(void); //按鍵操作

void gtxy(int x, int y) ; //控制游標移動的函數

int main(void)

{ while(1)

{csh( );

while(1)

{ inkey();

show();

if ( yes( ) )

{gtxy(6,12); printf("你成功了! 再來一局y/n?"); break;}

}

if(getch( )== ʹnʹ)break;

}

return 0;

}

void csh(void)

{r=0;

CONSOLE_CURSOR_INFO cursor_info={1,0}; //以下兩行是隱藏游標的設置

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);

for(i=0;i<4;i++) //給數組a依序賦值

for(j=0;j<4;j++)
{ if (i==3 && j==3) a[i][j]=0;
else a[i][j]=1+r++;
}

a[3][3]=a[1][1]; a[1][1]=0; //把a[3][3]與a[1][1]的值交換一下

m=1; n=1;

srand((unsigned)time(0)); //初始化隨機數發生器

for(r=0;r<500;r++) //將數組各值打亂
{k=rand( )%(4); //取0-3隨機數,分別代表上下左右四個方向
switch(k)
{ case 0: { up( );break; }
case 1: {down( );break; }
case 2: {left( );break; }
case 3: {rght( ); break; }
}
}

printf(" 數字拼圖");

printf(" ┌──────┬──────┬──────┬──────┐");

printf(" │ │ │ │ │");

printf(" ├──────┼──────┼──────┼──────┤");

printf(" │ │ │ │ │");

printf(" ├──────┼──────┼──────┼──────┤");

printf(" │ │ │ │ │");

printf(" ├──────┼──────┼──────┼──────┤");

printf(" │ │ │ │ │");

printf(" └──────┴──────┴──────┴──────┘");
show( );
}

void show(void)

{for(i=0;i<4;i++)

for(j=0;j<4;j++) //gtxy(7*j+9, 2*i+4)是游標到指定位置輸出數字

{gtxy(7*j+9,2*i+4); if(a[i][j]==0)printf(" │");

else if(a[i][j]>9)printf(" %d │",a[i][j]);

else printf(" %d │",a[i][j]);

}

}

void inkey(void)

{ int key;

key=getch( );
switch(key)
{ case 72: { up( ); break;}
case 80: {down( ); break; }
case 75: {left( ); break; }
case 77: {rght( );break;}
}
}

void up(void)

{ if (m!=3) //移動時要考慮空位"0"是否已經在邊界
{ a[m][n]=a[m+1][n]; m++; a[m][n]=0; }
}


void down(void)

{ if (m!=0)
{a[m][n]=a[m-1][n]; m--; a[m][n]=0; }
}

void left(void)

{ if (n!=3)
{ a[m][n]=a[m][n+1]; n++; a[m][n]=0;}
}
void rght(void)

{ if (n!=0)
{ a[m][n]=a[m][n-1]; n--; a[m][n]=0; }
}

int yes(void)

{ r=0;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{ if (a[i][j]!=1+r++) return (r==16)?1:0; }
}

void gtxy(int x, int y) //控制游標移動的函數

{ COORD coord;

coord.X = x;

coord.Y = y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

6. 話說有一個C代碼

個人感覺確實是多餘的。。。。。只需要後面一個就可以了。。。

7. 這個C源代碼有錯嗎

#include<stdio.h>//少了一個「#」號

/*函數聲明。下面的代碼將使用函數average*/
intaverage(inta,intb,intc);

voidmain(void)
{
inta=1,b=2,c=3;
inta2=1234,b2=2345,c2=3456;
inta3=9876,b3=2345,c3=1;
inty=average(a,b,c);
inty2=average(a2,b2,c2);
inty3=average(a3,b3,c3);
printf(" theaverageis%d",y);
printf(" theaverageis%d",y2);
printf(" theaverageis%d",y3);
getchar();
}

/*函數定義:具體的函數實現*/
/*
函數名:average
參數表:a,b,c:3個整型參數。
返回值:整型,返回3個整數的平均值
*/

intaverage(inta,intb,intc)//多寫了一個r字母
{
return(a+b+c)/3;
}

這是申明函數int average(int a,int b,int c);

average要更改的話,整個上下文的函數申明、調用和定義都要改成一樣的名稱

8. C代碼解釋!

我回復你的郵件總是被退回,我編譯好程序無法給你發送,其它內容就放在這里吧.
這是一款不錯的小游戲程序,程序很規范,我不知道你編譯出來沒有,程序沒錯誤,我已編譯出來了,你運行它,玩一下,程序代碼就好理解多了,有幾個函數的功能在這里說一下:
void DrawMan(int x, int y) 在指定坐標畫推箱子的人
void DrawSpace(int x, int y) 在指定坐標畫一個空格,用於抹掉原內容.
void DrawBox(int x, int y) 在指定坐標畫一個箱子,箱子用'@'表示,箱子沒有推到目標位.
void DrawDes(int x, int y) 在指定坐標畫一個箱子最終要被推到的位置.
void DrawBoxIn(int x, int y) 在指定坐標畫一個已經推到目標位的箱子.
void DrawMap(point *pman) 在指定坐標畫地圖
while (bioskey(1) == 0); 這是等著用戶按鍵,如果未探測到按鍵,再探的意思.
處理用戶按下方向鍵的程序要結合游戲當前狀態去理解,例如人物已位於地圖頂部,再按下向上的方向鍵,就無須任何操作.
歡迎常聯系.推箱子.exe文件大小是17711個位元組.創建和修改時間都是:2007年3月19日, 20:40:19,如果文件屬性有變,請不要運行,以免染毒.

9. c源代碼哪裡有下載

http://www.softhy.net/
這里有很多啊,什麼源代碼都有
http://www.newasp.net/code/dl003185
這里下C的源代碼

10. 哈夫曼編碼 C源代碼

#include <stdio.h>
#define MAXBIT 10 /*定義哈夫曼編碼的最大長度*/
#define MAXVALUE 10000 /*定義最大權值*/
#define MAXLEAF 30 /*定義哈夫曼樹中最多葉子節點個數*/
#define MAXNODE MAXLEAF*2-1 /*哈夫曼樹最多結點數*/
typedef struct { /*哈夫曼編碼信息的結構*/
int bit[MAXBIT];
int start;}Hcodetype;
typedef struct { /*哈夫曼樹結點的結構*/
int weight;
int parent;
int lchild;
int rchild;
}Hnodetype;
void huffmantree(Hnodetype huffnode[MAXNODE],int n) /*構造哈夫曼樹的函數*/
{
int i,j,m1,m2,x1,x2;
for(i=0;i<2*n-1;i++) /*存放哈夫曼樹結點的數組huffnode[]初始化*/
{
huffnode[i].weight=0;
huffnode[i].parent=-1;
huffnode[i].lchild=-1;
huffnode[i].rchild=-1;
}
for(i=0;i<n;i++) /*輸入入N個葉子節點的權值*/
{
printf("please input %d character's weight\n",i);
scanf("%d",&huffnode[i].weight);
}
for(i=0;i<n-1;i++) /*開始循環構造哈夫曼樹*/
{
m1=m2=MAXVALUE;
x1=x2=0;
for(j=0;j<n+i;j++)
{
if(huffnode[j].weight<m1&&huffnode[j].parent==-1)
{
m2=m1;x2=x1;m1=huffnode[j].weight;x1=j;
}
else if(huffnode[j].weight<m2&&huffnode[j].parent==-1)
{
m2=huffnode[j].weight;x2=j;
}
}
huffnode[x1].parent=n+i;
huffnode[x2].parent=n+i;
huffnode[n+i].weight=huffnode[x1].weight+huffnode[x2].weight;
huffnode[n+i].lchild=x1;
huffnode[n+i].rchild=x2;
}
}
void main()
{
Hnodetype huffnode[MAXNODE];
Hcodetype huffcode[MAXLEAF],cd;
int i,j,c,p,n;
printf("please input n\n");
scanf("%d",&n); /*輸入葉子節點個數*/
huffmantree(huffnode,n); /*建立哈夫曼樹*/
for(i=0;i<n;i++) /*該循環求每個葉子節點對應字元的哈夫曼編碼*/
{
cd.start=n-1;c=i;
p=huffnode[c].parent;
while(p!=-1)
{
if(huffnode[p].lchild==c) cd.bit[cd.start]=0;
else cd.bit[cd.start]=1;
cd.start--;c=p;
p=huffnode[c].parent;
}
for(j=cd.start+1;j<n;j++) /*保存求出的每個葉節點的哈夫曼編碼和編碼的起始位*/
huffcode[i].bit[j]=cd.bit[j];
huffcode[i].start=cd.start;
}
for(i=0;i<n;i++) /*輸出每個葉子節點的哈夫曼編碼*/
{
printf("%d character is:",i);
for(j=huffcode[i].start+1;j<n;j++)
printf("%d",huffcode[i].bit[j]);
printf("\n");
}
}

熱點內容
上傳文件文件夾找不到 發布:2024-09-20 00:26:32 瀏覽:914
承台箍筋加密區 發布:2024-09-20 00:26:31 瀏覽:227
筆記本什麼配置能流暢運行cf 發布:2024-09-20 00:14:19 瀏覽:951
實測華為編譯器 發布:2024-09-19 23:50:52 瀏覽:821
linux匯總 發布:2024-09-19 23:46:39 瀏覽:452
阿里雲伺服器環境搭建教程 發布:2024-09-19 23:21:58 瀏覽:837
黃色文件夾圖標 發布:2024-09-19 23:19:22 瀏覽:684
mysql資料庫導出導入 發布:2024-09-19 23:00:47 瀏覽:183
lua腳本精靈 發布:2024-09-19 23:00:41 瀏覽:659
任務欄文件夾圖標 發布:2024-09-19 22:54:25 瀏覽:101