當前位置:首頁 » 編程語言 » 200行c語言源代碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

200行c語言源代碼

發布時間: 2022-09-22 00:19:33

『壹』 中分,緊急求個200行左右的c語言源代碼!

#include <iostream.h>
#include <fstream.h>
int mark[]; //右來保存走法的
int num[2][2];//棋盤
int temp;
int k ;
int q ;
string strAim = "123804765" //目標字元串,空格用0表示
string States[100];//字元竄數組
int iQuick; //有來退出遞歸的標志,1,表示找到走法,可以退出,0,怎麼沒有找到走法,繼續走
Hrd(int i,int j)//華龍道演算法,好像能找到結果,但是不能找到最少步數的結果,我不確定會不會還有漏洞。結果保存在mark[]中
{ string str1;
if (i!=0) //如果可以向上走,則向上走一步
{
temp=num[i-1][j];
num[i-1][j]=num[i][j];
num[i][j]=temp ; //交換空格和它上面的數字

// 保存交換後的狀態
str1=Change2Str(num[][]); //轉化成字元串,用來比較
if (CompState(str1)) //比較變換後的狀態是否在以前的狀態中出現過
{
//如果以前出現過,則返回
temp=num[i-1][j];
num[i-1][j]=num[i][j];
num[i][j]=temp ; // 把原來交換過的數字再交換過來
return ;
}
else//比較後,發現目前的狀態以前沒有出現過
{ mark[k++]=1 ;
if(strcmp(&strAim,& str1)=1)//跟目標比,看是否相等
{
iquick=1;
return;

}
else //不相等,沒有達到最後我們的要求
{
//1 代表向上走了一步
Add2States(str1); //保存現在的狀態到狀態數組中
Hrd(i-1,j);
if (iquick=1) //可以退出
{
return;
}
} //遞歸,繼續遍歷
}

}
if(j!=2)//如果可以向右走,則向右走一步
{
temp=num[i][j+1];
num[i][j+1]=num[i][j] ;
num[i][j]=temp;

// 保存交換後的狀態
str1=Change2Str(num[][]); //轉化成字元串,用來比較
if (CompState(str1)) //比較變換後的狀態是否在以前的狀態中出現過
{
//如果以前出現過,返回
temp=num[i][j+1];
num[i][j+1]=num[i][j] ;
num[i][j]=temp; // 把原來交換過的數字再交換過來
return;
}
else//比較後,發現目前的狀態以前沒有出現過
{ mark[k++]=2 ; //2 代表向右走了一步
if(strcmp(&strAim,& str1)=1)//跟目標比,看是否相等
{
iquick=1;
return;

}
else //沒有達到結果
{

Add2States(str1); //保存現在的狀態到狀態數組中
Hrd(i,j+1) ; //遞歸,繼續遍歷
if (iquick=1)
{
return;
}
}
}

}
if (i!=2)// 如果可以向下走,則向下走一步
{
temp=num[i+1][j];
num[i+1][j]=num[i][j];
num[i][j]=temp;

// 保存交換後的狀態
str1=Change2Str(num[][]); //轉化成字元串,用來比較
if (CompState(str1)) //比較變換後的狀態是否在以前的狀態中出現過
{
//如果以前出現過,則返回
temp=num[i+1][j];
num[i+1][j]=num[i][j];
num[i][j]=temp; // 把原來交換過的數字再交換過來
return ;
}
else//比較後,發現目前的狀態以前沒有出現過
{ mark[k++]=3 ; //3 代表向下走了一步
if(strcmp(&strAim,& str1)=1)//跟目標比,看是否相等
{
iquick=1;
return;

}
else //沒有達到最後我們的要求
{

Add2States(str1); //保存現在的狀態到狀態數組中
Hrd(i+1,j) ; //遞歸,繼續遍歷
if (iquick=1)
{
return;
}
}
}
}
if (j!=0)//如果可以向左走,則向左走一步
{
temp=num[i1][j-1];

num[i][j-1]=num[i][j];
num[i][j]=temp;

// 保存交換後的狀態
str1=Change2Str(num[][]); //轉化成字元串,用來比較
if (CompState(str1)) //比較變換後的狀態是否在以前的狀態中出現過
{
//如果以前出現過,則回溯
temp=num[i][j-1];
num[i][j-1]=num[i][j];
num[i][j]=temp; // 把原來交換過的數字再交換過來

return ;
}
else//比較後,發現目前的狀態以前沒有出現過
{ mark[k++]=4 ; //1 代表向右走了一步
if(strcmp(&strAim,& str1)=1)//跟目標比,看是否相等
{
iquick=1;
return;

}
else //沒有達到最後我們的要求
{
Add2States(str1); //保存現在的狀態到狀態數組中
Hrd(i,j-1) ; //遞歸,繼續遍歷
if (iquick=1)
{
return;
}
}
}

}
//如果都走過了,則返回
k--;
return;

}

void Change2Str(int arr[][])// 把二維數組轉換成一個字元串
{int i,j
string strState
for (i=0;i<3 ;i++ )
{ for (j=0;j<3 ;j++ )
{
strState= strState & arr[i][j];
}
}
return strState;
}

void CompState(string str1 )//比較當前的狀態是否再以前的狀態中出現過
{ int i;
for (i=0;i<len(states[])-1 ; i++)//len(states[]),取得數組的長度,有點忘了
{
if (strcmp(&States[i],&str1)!=0)//如果兩個字元串相等,則函數返回true
{
return true;
}
}
return false;
}
Add2States(string str1)
{
States[q++]=str1 ;
}

main()
{ num[0][0]=1;
num[0][1]=2;
num[0][2]=3;
num[1][0]=8;
num[1][1]=6;
num[1][2]=4;
num[2][0]=1;
num[2][1]=0;
num[2][2]=5;
hrd(2,1);
for(int i=0 ,i<100,i++)
{count<<mark[i]<<endl;
}
}
Dim moveup As Integer '蛇向上轉向的標志
Dim movedown As Integer
Dim moveleft As Integer
Dim moveright As Integer

Public u As Integer 'u,l,r,d為蛇轉向時的控制數值
Public d As Integer
Public l As Integer
Public r As Integer

Public score As Integer '游戲分數

Public speed As Integer '游戲速度

Public pause As Boolean '游戲暫停標志

Public gamebegin As Boolean '游戲開始標志

Public s As Integer '蛇的當前長度,開始時設為6

Public eatd As Boolean '蛇是否吃到食物的標志

Public lastx As Integer '若蛇吃到食物,lastx,lasty用來存放當前最後一個shape的運動狀態,以供設定新的shape運動狀態之用
Public lasty As Integer

Option Base 1
Dim X(100) As Long '數組存放蛇的長度
Dim Y(100) As Long

Public Sub eat() '判斷蛇是否吃到食物的函數

If X(1) = -200 Then
If Shape1(1).Left <= Shape2.Left And Shape1(1).Top = Shape2.Top Then
eatd = True
End If
End If

If Y(1) = -200 Then
If Shape1(1).Top <= Shape2.Top And Shape1(1).Left = Shape2.Left Then
eatd = True
End If
End If

If X(1) = 200 Then
If Shape1(1).Left >= Shape2.Left + 200 And Shape1(1).Top = Shape2.Top Then
eatd = True
End If
End If

If Y(1) = 200 Then
If Shape1(1).Top >= Shape2.Top + 200 And Shape1(1).Left = Shape2.Left Then
eatd = True
End If
End If
End Sub
Public Sub ensure_position() '此函數確定新的shape1(s)的位置
If X(s - 1) = -200 Then
Shape1(s).Left = Shape1(s - 1).Left + 200: Shape1(s).Top = Shape1(s - 1).Top
End If
If Y(s - 1) = -200 Then
Shape1(s).Left = Shape1(s - 1).Left: Shape1(s).Top = Shape1(s - 1).Top + 200
End If
If X(s - 1) = 200 Then
Shape1(s).Left = Shape1(s - 1).Left - 200: Shape1(s).Top = Shape1(s - 1).Top
End If
If Y(s - 1) = 200 Then
Shape1(s).Left = Shape1(s - 1).Left: Shape1(s).Top = Shape1(s - 1).Top - 200
End If
End Sub
Public Sub ensure_state() '此過程用來確定新的控制項的初始運動狀態

If X(1) = -200 Then
If moveleft = 1 Then
X(s) = X(s - 1): Y(s) = Y(s - 1)
Else
X(s) = lastx: Y(s) = lasty
End If
End If

If Y(1) = -200 Then
If moveup = 1 Then
X(s) = X(s - 1): Y(s) = Y(s - 1)
Else
X(s) = lastx: Y(s) = lasty
End If
End If

If X(1) = 200 Then
If moveright = 1 Then
X(s) = X(s - 1): Y(s) = Y(s - 1)
Else
X(s) = lastx: Y(s) = lasty
End If
End If

If Y(1) = 200 Then
If movedown = 1 Then
X(s) = X(s - 1): Y(s) = Y(s - 1)
Else
X(s) = lastx: Y(s) = lasty
End If
End If
End Sub

Public Sub strike_oneself() '測試蛇頭是否撞到自己

Dim i
Dim j: j = 0
If Y(1) = 200 Then '蛇頭向下撞到自己
For i = 7 To s '蛇頭只能和第六塊或以後的蛇身相撞
If Shape1(1).Top = Shape1(s).Top And Shape1(1).Left = Shape1(s).Left Then
Form1.initialize
Form1.outputmessage
Exit For
End If
Next i
End If

If X(1) = 200 Then '蛇頭向右撞到自己
For i = 7 To s
If Shape1(1).Left = Shape1(i).Left - 200 And Shape1(1).Top = Shape1(i).Top Then
Form1.initialize
Form1.outputmessage
Exit For
End If
Next i
End If

If Y(1) = -200 Then '蛇頭向上撞到自己
For i = 7 To s
If Shape1(1).Top = Shape1(i).Top + 200 And Shape1(1).Left = Shape1(i).Left Then
Form1.initialize
Form1.outputmessage
Exit For
End If
Next i
End If

If X(1) = -200 Then '蛇頭向左撞到自己
For i = 7 To s
If Shape1(1).Left = Shape1(i).Left + 200 And Shape1(1).Top = Shape1(i).Top Then
Form1.initialize
Form1.outputmessage
Exit For
End If
Next i
End If

End Sub
Public Sub strike_wall() '測試蛇頭是否撞到牆壁
If Shape1(1).Top < 0 Or Shape1(1).Top > Line1.Y1 - 200 Or Shape1(1).Left < 0 Or Shape1(1).Left > Form1.Width - 200 Then
Form1.outputmessage
Form1.initialize
End If
End Sub
Public Sub outputmessage() ' 游戲結束後的輸出信息
gameovermessage = "GAME OVER!"
dx = (8000 - TextWidth(gameovermessage)) / 2 '在窗體中間輸出"GAME OVER!"和得分
dy = (6000 - TextHeight(gameovermessage)) / 2
CurrentX = dx: CurrentY = dy
Form1.Print gameovermessage
scoremessage = "你的得分:" + Text1.Text
dx = (8000 - TextWidth(scoremessage)) / 2
dy = dy + TextHeight(scoremessage)
CurrentX = dx: CurrentY = dy
Form1.Print scoremessage
End Sub
Public Sub initialize() '游戲結束(失敗)後,游戲初始化函數
moveup = 0
movedown = 0
moveleft = 0
moveright = 0
u = 0: d = 0: l = 0: r = 0
Label5.Caption = "停止"

For i = 1 To s ' 初始化蛇的位置和狀態
Shape1(i).Left = 1200 + (6 - i) * 200
Shape1(i).Top = 5000
X(i) = 200
Y(i) = 0
Next i
If s > 6 Then
For i = 7 To s
Unload Shape1(i) '卸載多餘的shape,使初始的shape個數為六個
Next i
End If

'以下的這段是用來查看游戲初始化時的中的參數
'CurrentX = 0: CurrentY = 0
'Form1.FontSize = 10
'Print moveup: Print movedown: Print moveleft: Print moveright
'Print u: Print r: Print l: Print d
'For i = 1 To s
'Print X(i): Print Y(i)
'Next i

s = 6
Timer1.Enabled = False
gamebegin = False '游戲未開始
pause = False
HScroll1.Enabled = True
End Sub

Private Sub Command1_Click()
Timer1.Enabled = False
Dim r
r = MsgBox("你真的要退出嗎?", 33, "警告")
If r = 1 Then
Unload Form1
Else
Timer1.Enabled = True
End If

End Sub

Private Sub Form_KeyPress(keyascii As Integer)

If gamebegin = True And pause = False Then '只有游戲處於開始時方向鍵才有效
'下面四個if語句是蛇的方向控制函數
If keyascii = 119 Then
If Y(1) <> 200 Then '只有當蛇頭不正好向下運動時,按下向上才有效
moveup = 1 '向下上為w
End If
End If

If keyascii = 97 Then '向左為a
If X(1) <> 200 Then
moveleft = 1
End If
End If

If keyascii = 115 Then '向下為s
If Y(1) <> -200 Then
movedown = 1
End If
End If

If keyascii = 100 Then '向右為d
If X(1) <> -200 Then
moveright = 1
End If
End If
End If

If keyascii = 32 Then '判斷游戲是否在開始,按下空格鍵開始,否則按下空格鍵為暫停
If gamebegin = False Then
Timer1.Enabled = True
Label5.Caption = "開始"
Form1.Cls
score = 0
Text1.Text = Str$(score)
HScroll1.Enabled = False
gamebegin = True

Else
If pause = True Then '判斷暫停與否
Timer1.Enabled = True
Label5.Caption = "開始"
Else
Timer1.Enabled = False
Label5.Caption = "暫停"
End If
pause = Not pause
End If
End If

End Sub

Private Sub Form_Load() '對各參數的初始化
moveup = 0
moveleft = 0
moveright = 0
movedown = 0
u = 0: l = 0: d = 0: r = 0
s = 6 '蛇的初始長度
eatd = False
gamebegin = False
pause = False
speed = HScroll1.Value '初始速度
Label5.Caption = "停止"

Dim i
For i = 1 To s '蛇的初始運動方向
X(i) = 200
Y(i) = 0
Next i

Timer1.Enabled = False '沒開始游戲
Shape2.Left = 200 * Int(30 * Rnd) '貪吃蛇的食物的位置初始化
Shape2.Top = 200 * Int(30 * Rnd)

End Sub
Private Sub HScroll1_Change()
speed = HScroll1.Value
End Sub

Private Sub Timer1_Timer()

Timer1.Interval = 150 / speed '游戲速度

If movedown = 1 Then '按下下方向鍵,蛇向下轉向
d = d + 1
X(d) = 0: Y(d) = 200
If d = s Then
movedown = 0: d = 0
End If
End If

If moveup = 1 Then '按下向上方向鍵,蛇向上轉向
u = u + 1
X(u) = 0: Y(u) = -200
If u = s Then
moveup = 0: u = 0
End If
End If

If moveleft = 1 Then '向左
l = l + 1
X(l) = -200: Y(l) = 0
If l = s Then
moveleft = 0: l = 0
End If
End If

If moveright = 1 Then '向右
r = r + 1
X(r) = 200: Y(r) = 0
If r = s Then
moveright = 0: r = 0
End If
End If

Dim i '蛇的運動代碼
For i = 1 To s
Shape1(i).Left = Shape1(i).Left + X(i)
Shape1(i).Top = Shape1(i).Top + Y(i)
Next i

Form1.eat '調用過程eat(),判斷蛇是否吃了食物

If eatd = True Then
score = score + 5 * HScroll1.Value
Text1.Text = Str$(score)
Shape2.Left = 200 * Int(30 * Rnd) '如果食物被吃則隨機產生貪吃蛇的食物的位置
Shape2.Top = 200 * Int(30 * Rnd)
Shape2.FillColor = RGB(Int(255 * Rnd), Int(255 * Rnd), Int(255 * Rnd)) '隨機產生食物的顏色
If Shape2.FillColor = &H0& Then
Shape2.FillColor = RGB(100, 150, 200)
End If
lastx = X(s) '蛇吃到食物,lastx,lasty用來存放當前最後一個shape的運動狀態-
lasty = Y(s) '-以供設定新的shape運動狀態之用
s = s + 1
Load Shape1(s) '產生新的控制項shape1數組,使蛇的長度加長
Form1.ensure_state '調用設定新的shape控制項的運動狀態過程
Form1.ensure_position '設定新的shape1的位置
Shape1(s).Visible = True
eatd = False
End If

Form1.strike_oneself '測試游戲是否失敗的函數
Form1.strike_wall

End Sub

『貳』 用c語言編寫的一個小程序,200行以上,急!!!

摘要 #includeint zuheshu(float s[],int n); // 組合數的函數

『叄』 請大家給我一些200條以上的C語言程序,謝了!!

抄一個大數加減乘除程序給你。218行。

#include <stdio.h>
#define MAXINT 1000
int compare(int a[],int b[]);
int bigplus(int a[],int b[],int c[]);
int bigsub(int a[],int b[],int c[]);
int bigmult(int a[],unsigned int b,int c[]);
int bigmult2(int a[],int b[],int c[]);
int bigdiv(int a[],unsigned int b,int c[],int *d);
int bigdiv2(int a[],int b[],int c[],int d[]);
int main(int argc, char *argv[])
{
int a[MAXINT]={10,5,4,6,5,4,3,2,1,1,1}; //被乘數或被除數
int b[MAXINT]={7,7,6,5,4,3,2,1}; //乘數或除數
int c[MAXINT],d[MAXINT]; //c[]存放商,d[]存放余數
int div=1234; //小乘數或小除數
int k=0;
int *res=&k; //小余數整數指針
bigplus(a,b,c);
bigsub(a,b,c);
bigmult(a,div,c);
bigmult2(a,b,c);
bigdiv(a,div,c,res);
bigdiv2(a,b,c,d);
getchar();
return 0;
}
int compare(int a[],int b[]) //比較大整數的大小
{
int i;
if (a[0]>b[0]) return 1; //比較a,b的位數確定返回值
else if (a[0]<b[0]) return -1;
else //位數相等時的比較
{
i=a[0];
while (a[i]==b[i]) //逐位比較
i--;
if (i==0) return 0;
else if (a[i]>b[i]) return 1;
else return -1;
}
}
int bigplus(int a[],int b[],int c[]) //大整數加法
{
int i,len;
len=(a[0]>b[0]?a[0]:b[0]); //a[0] b[0]保存數組長度,len為較長的一個
for(i=0;i<MAXINT;i++) //將數組清0
c[i]=0;
for (i=1;i<=len;i++) //計算每一位的值
{
c[i]+=(a[i]+b[i]);
if (c[i]>=10)
{
c[i]-=10; //大於10的取個位
c[i+1]++; //高位加1
}
}
if (c[i+1]>0) len++;
c[0]=len; //c[0]保存結果數組實際長度
printf("Big integers add: ";
for (i=len;i>=1;i--)
printf("%d",c[i]); //列印結果
printf("\n";
return 0;
}
int bigsub(int a[],int b[],int c[]) //大整數減法
{
int i,len;
len=(a[0]>b[0]?a[0]:b[0]); //a[0]保存數字長度,len為較長的一個
for(i=0;i<MAXINT;i++) //將數組清0
c[i]=0;
if (compare(a,b)==0) //比較a,b大小
{
printf("Result:0";
return 0;
}
else if (compare(a,b)>0)
for (i=1;i<=len;i++) //計算每一位的值
{
c[i]+=(a[i]-b[i]);
if (c[i]<0)
{
c[i]+=10; //小於0的原位加10
c[i+1]--; //高位減1
}
}
else
for (i=1;i<=len;i++) //計算每一位的值
{
c[i]+=(b[i]-a[i]);
if (c[i]<0)
{
c[i]+=10; //小於0原位加10
c[i+1]--; //高位減1
}
}
while (len>1 && c[len]==0) //去掉高位的0
len--;
c[0]=len;
printf("Big integers sub= ";
if (a[0]<b[0]) printf("-";
for(i=len;i>=1;i--) //列印結果
printf("%d",c[i]);
printf("\n";
return 0;
}
int bigmult(int a[],unsigned int b,int c[])//高精度乘以低精度
{
int len,i;
for (i=0;i<MAXINT;i++) //數組清0
c[i]=0;
len=a[0];
for(i=1;i<=len;i++) //對每一位計算
{
c[i]+=a[i]*b;
c[i+1]+=c[i]/10;
c[i]%=10;
}
while (c[++len]>=10) //處理高位
{
c[len+1]=c[len]/10;
c[len]%=10;
}
if (c[len]==0) len--; //處理高進位為0情況
printf("Big integrs multi small integer: ";
for (i=len;i>=1;i--)
printf("%d",c[i]);
printf("\n";
}
int bigmult2(int a[],int b[],int c[]) //高精度乘以高精度
{
int i,j,len;
for (i=0;i<MAXINT;i++) //數組清0
c[i]=0;
for (i=1;i<=a[0];i++) //被乘數循環
for (j=1;j<=b[0];j++) //乘數循環
{
c[i+j-1]+=a[i]*b[j]; //將每一位計算累加
c[i+j]+=c[i+j-1]/10; //將每一次結果累加到高一位
c[i+j-1]%=10; //計算每一次的個位
}
len=a[0]+b[0]; //取最大長度
while (len>1 && c[len]==0) //去掉高位0
len--;
c[0]=len;
printf("Big integers multi: ";
for (i=len;i>=1;i--) //列印結果
printf("%d",c[i]);
printf("\n";
}
int bigdiv(int a[],unsigned int b,int c[],int *d) //高精度除以低精度
{ //a[] 為被乘數,b為除數,c[]為結果,d為余數
int i,len;
len=a[0]; //len為a[0]的數組長度
for (i=len;i>=1;i--)
{
(*d)=10*(*d)+a[i]; //計算每一步余數
c[i]=(*d)/b; //計算每一步結果
(*d)=(*d)%b; //求模余數
}
while (len>1 && c[len]==0) len--; //去高位0
printf("Big integer div small integer: ";
for (i=len;i>=1;i--) //列印結果
printf("%d",c[i]);
printf("\tArithmetic compliment:%d",*d);
printf("\n";
}
int bigdiv2(int a[],int b[],int c[],int d[]) //高精度除以高精度
{
int i,j,len;
if (compare(a,b)<0) //被除數較小直接列印結果
{
printf("Result:0";
printf("Arithmetic compliment:";
for (i=a[0];i>=1;i--) printf("%d",a[i]);
printf("\n";
return -1;
}
for (i=0;i<MAXINT;i++) //商和余數清0
{
c[i]=0;
d[i]=0;
}
len=a[0];d[0]=0;
for (i=len;i>=1;i--) //逐位相除
{
for (j=d[0];j>=1;j--)
d[j+1]=d[j];
d[1]=a[i]; //高位*10+各位
d[0]++; //數組d長度增1
while (compare(d,b)>=0) //比較d,b大小
{
for (j=1;j<=d[0];j++) //做減法d-b
{
d[j]-=b[j];
if (d[j]<0)
{
d[j]+=10;
d[j+1]--;
}
}
while (j>0 && d[j]==0) //去掉高位0
j--;
d[0]=j;
c[i]++; //商所在位值加1
}
}
j=b[0];
while (c[j]==0 && j>0) j--; //求商數組c長度
c[0]=j;
printf("Big integers div result: ";
for (i=c[0];i>=1;i--) //列印商
printf("%d",c[i]);
printf("\tArithmetic compliment: "; //列印余數
for (i=d[0];i>=1;i--)
printf("%d",d[i]);
printf("\n");
}

『肆』 急求啊,寫一個200行的C語言程序,什麼都可以,帶解釋,哪位大神幫幫忙

#include<stdio.h>
#defineOK1
#defineERROR0
#defineTRUE1
#defineFALSE0
#defineMAXSIZE100
#defineLElemTypeint
#defineStatusint
#defineBOOLint
typedefstruct
{
LElemTypedata;
intcur;
}Component,SLinkList[MAXSIZE];
intMalloc(SLinkListspace)
{
//若備用鏈表非空,則返回分配的結點下標(備用鏈表的第一個結點),否則返回0
inti=space[0].cur;
if(i)
space[0].cur=space[i].cur;
returni;
}
StatusFree(SLinkListspace,intk)
{
//將下標為空的空閑結點回收到備用鏈表(成為備用鏈表的第一個結點)
space[k].cur=space[0].cur;
space[0].cur=k;
returnOK;
}
StatusInitList(SLinkListL)
{
//構造一個空的鏈表L,表頭為L的最後一個單元L[MAXSIZE-1],其餘單元鏈成
//一個備用鏈表,表頭為L的第一個單元L[0],「0」表示空指針
inti;
L[MAXSIZE-1].cur=0;
for(i=0;i<MAXSIZE-2;i++)
L[i].cur=i+1;
L[MAXSIZE-2].cur=0;
returnOK;
}
StatusClearList(SLinkListL)
{
//初始條件:線性表L已存在。操作結果:將L重置為空表
inti,j,k;
i=L[MAXSIZE-1].cur;
L[MAXSIZE-1].cur=0;
k=L[0].cur;
L[0].cur=i;
while(i)
{
j=i;
i=L[i].cur;
}
L[j].cur=k;
returnOK;
}
BOOLListEmpty(SLinkListL)
{
//若L是空表,返回TRUE;否則返回FALSE
if(!L[MAXSIZE-1].cur)
returnTRUE;
else
returnFALSE;
}
intListLength(SLinkListL)
{
//返回L中數據元素個數
inti,len;
i=L[MAXSIZE-1].cur;
len=0;
while(i)
{
i=L[i].cur;
len++;
}
returnlen;
}
StatusGetElem(SLinkListL,inti,LElemType*e)
{
//用e返回L中第i個元素的值
intj,k=MAXSIZE-1;
if(i<1||i>ListLength(L))
returnERROR;
for(j=1;j<=i;j++)
k=L[k].cur;
*e=L[k].data;
returnOK;
}
intLocateElem(SLinkListL,LElemTypee)
{
//在靜態單鏈線性表L中查找第1個值為e的元素。若找到,則返回它在L中的
//位序,否則返回0。(與其它LocateElem()的定義不同)
inti=L[MAXSIZE-1].cur;
while(i&&L[i].data!=e)
i=L[i].cur;
returni;
}
StatusPriorElem(SLinkListL,LElemTypecur_e,LElemType*pre_e)
{
//初始條件:線性表L已存在
//操作結果:若cur_e是L的數據元素,且不是第一個,則用pre_e返回它的前驅,
//否則操作失敗,pre_e無定義
inti,j;
i=L[MAXSIZE-1].cur;
do{
j=i;
i=L[i].cur;
}while(i&&L[i].data!=cur_e);
if(i)
{
*pre_e=L[j].data;
returnOK;
}
returnERROR;
}
StatusNextElem(SLinkListL,LElemTypecur_e,LElemType*next_e)
{
//初始條件:線性表L已存在
//操作結果:若cur_e是L的數據元素,且不是最後一個,則用next_e返回它的後繼,
//否則操作失敗,next_e無定義
inti,j;
i=LocateElem(L,cur_e);
if(i)
{
j=L[i].cur;
if(j)
{
*next_e=L[j].data;
returnOK;
}
}
returnERROR;
}
StatusListInsert(SLinkListL,inti,LElemTypee)
{
//在L中第i個元素之前插入新的數據元素e
intj,k,l;
k=MAXSIZE-1;
if(i<1||i>ListLength(L)+1)
returnERROR;
j=Malloc(L);
if(j)
{
L[j].data=e;
for(l=1;l<=i-1;l++)
k=L[k].cur;
L[j].cur=L[k].cur;
L[k].cur=j;
returnOK;
}
returnERROR;
}
StatusListDelete(SLinkListL,inti,LElemType*e)
{
//刪除在L中第i個數據元素e,並返回其值
intj,k;
if(i<1||i>ListLength(L))
returnERROR;
k=MAXSIZE-1;
for(j=1;j<=i-1;j++)
k=L[k].cur;
j=L[k].cur;
L[k].cur=L[j].cur;
*e=L[j].data;
Free(L,j);
returnOK;
}
StatusListTraverse(SLinkListL,void(*visit)(LElemTypee))
{
inti=L[MAXSIZE-1].cur;
while(i)
{
visit(L[i].data);
i=L[i].cur;
}
returnOK;
}
voidVisit(LElemTypee)
{
printf("%d ",e);
}
intmain()
{
inti,j,k;
LElemTypee,e0;
SLinkListL;
InitList(L);
for(j=1;j<=5;j++)
i=ListInsert(L,1,j);
ListTraverse(L,Visit);
//判斷鏈表是否為空
i=ListEmpty(L);
printf("%d ",i);
//列印鏈表長度
printf("%d ",ListLength(L));
//清空靜態鏈表
ClearList(L);
ListTraverse(L,Visit);
for(j=1;j<=10;j++)
ListInsert(L,j,j);
//插入新節點後
ListTraverse(L,Visit);
//獲取鏈表中的第5個元素
GetElem(L,5,&e);
printf("%d ",e);
for(j=0;j<=1;j++)
{
k=LocateElem(L,j);
if(k)
printf("%d%d ",j,k);//j在鏈表中的序號k
else
printf("Can'tfind%d ",j);//鏈表中不存在j
}
for(j=1;j<=2;j++)//測試頭兩個數據
{
GetElem(L,j,&e0);//把第j個數據賦給e0
i=PriorElem(L,e0,&e);//求e0的前驅
if(!i)
printf("Noelembefore%d ",e0);
else
printf("Elembefore%dis%d ",e0,e);//數據e0的前驅
}
for(j=ListLength(L)-1;j<=ListLength(L);j++)//最後兩個數據
{
GetElem(L,j,&e0);//把第j個數據賦給e0
i=NextElem(L,e0,&e);//求e0的後繼
if(!i)
printf("Noelemafter%d ",e0);
else
printf("Theelemafter%is%d ",e0,e);//數據e0的後繼
}
k=ListLength(L);//k為表長
for(j=k+1;j>=k;j--)
{
i=ListDelete(L,j,&e);//刪除第j個數據
if(i)
printf("DeleteSuccussfully ");
else
printf("Can'tfindtheelem ",j);
}
ListTraverse(L,Visit);
return0;
}

給你找了個靜態鏈表的代碼,能編譯運行

『伍』 C語言期末課程設計,老師讓寫至少200行源代碼,請大俠們幫幫我啊,真心不會寫啊。

LZ 涉及到的C語言是 用 WinTC編譯的 還是 單片機系列的 C語言啊?

『陸』 求C語言200行以上的程序2個

期末的作業吧?呵呵 給你兩個:

一、題目:家庭財務管理小程序
2.程序源代碼:

/*money management system*/
#include "stdio.h"
#include "dos.h"
main()
{
FILE *fp;
struct date d;
float sum,chm=0.0;
int len,i,j=0;
int c;
char ch[4]="",ch1[16]="",chtime[12]="",chshop[16],chmoney[8];
pp: clrscr();
sum=0.0;
gotoxy(1,1);printf("|----------------------------------------------------|");
gotoxy(1,2);printf("| money management system(C1.0) 2000.03 |");
gotoxy(1,3);printf("|----------------------------------------------------|");
gotoxy(1,4);printf("| -- money records -- | -- today cost list -- |");
gotoxy(1,5);printf("| ------------------------ |-----------------------------|");
gotoxy(1,6);printf("| date: -------------- | |");
gotoxy(1,7);printf("| | | | |");
gotoxy(1,8);printf("| -------------- | |");
gotoxy(1,9);printf("| thgs: ------------------ | |");
gotoxy(1,10);printf("| | | | |");
gotoxy(1,11);printf("| ------------------ | |");
gotoxy(1,12);printf("| cost: ---------- | |");
gotoxy(1,13);printf("| | | | |");
gotoxy(1,14);printf("| ---------- | |");
gotoxy(1,15);printf("| | |");
gotoxy(1,16);printf("| | |");
gotoxy(1,17);printf("| | |");
gotoxy(1,18);printf("| | |");
gotoxy(1,19);printf("| | |");
gotoxy(1,20);printf("| | |");
gotoxy(1,21);printf("| | |");
gotoxy(1,22);printf("| | |");
gotoxy(1,23);printf("|--------------------------------------------------|");
i=0;
getdate(&d);
sprintf(chtime,"%4d.%02d.%02d",d.da_year,d.da_mon,d.da_day);
for(;;)
{
gotoxy(3,24);printf(" Tab __browse cost list Esc __quit");
gotoxy(13,10);printf(" ");
gotoxy(13,13);printf(" ");
gotoxy(13,7);printf("%s",chtime);
j=18;
ch[0 ]=getch();
if(ch[0]==27)
break;
strcpy (chshop,"");
strcpy(chmoney,"");
if(ch[0]==9)
{
mm:i=0;
fp=fopen("home.dat","r+");
gotoxy(3,24);printf(" ");
gotoxy(6,4);printf(" list records ");
gotoxy(1,5);printf("|-------------------------------------|");
gotoxy(41,4);printf(" ");
gotoxy(41,5);printf(" |");
while(fscanf(fp,"%10s%14s%f\n",chtime,chshop,&chm)!=EOF)
{
if(i==36)
{
getch();
i=0;
}
if ((i%36)<17)
{
gotoxy(4,6+i);
printf(" ");
gotoxy(4,6+i);
}
else
if((i%36)>16)
{
gotoxy(41,4+i-17);
printf(" ");
gotoxy(42,4+i-17);
}
i++;
sum=sum+chm;
printf("%10s %-14s %6.1f\n",chtime,chshop,chm);}
gotoxy(1,23);printf("|----------------------------------------------|");
gotoxy(1,24);printf("| |");
gotoxy(1,25);printf("|----------------------------------------------|");
gotoxy(10,24);printf("total is %8.1f$",sum);
fclose(fp);
gotoxy(49,24);printf("press any key to.....");getch();goto pp;
}
else
{
while(ch[0]!='\r')
{
if(j<10)
{
strncat(chtime,ch,1);
j++;
}
if(ch[0]==8)
{
len=strlen(chtime)-1;
if(j>15)
{
len=len+1;
j=11;
}
strcpy(ch1,"");
j=j-2;
strncat(ch1,chtime,len);
strcpy(chtime,"");
strncat(chtime,ch1,len-1);
gotoxy(13,7);printf(" ");
}
gotoxy(13,7);printf("%s",chtime);ch[0]=getch();
if(ch[0]==9)
goto mm;
if(ch[0]==27)
exit(1);
}
gotoxy(3,24);printf(" ");
gotoxy(13,10);
j=0;
ch[0]=getch();
while(ch[0]!='\r')
{
if (j<14)
{
strncat(chshop,ch,1);
j++;
}
if(ch[0]==8)
{
len=strlen(chshop)-1;
strcpy(ch1,"");
j=j-2;
strncat(ch1,chshop,len);
strcpy(chshop,"");
strncat(chshop,ch1,len-1);
gotoxy(13,10);printf(" ");
}
gotoxy(13,10);printf("%s",chshop);ch[0]=getch();}
gotoxy(13,13);
j=0;
ch[0]=getch();
while(ch[0]!='\r')
{
if (j<6)
{
strncat(chmoney,ch,1);
j++;
}
if(ch[0]==8)
{
len=strlen(chmoney)-1;
strcpy(ch1,"");
j=j-2;
strncat(ch1,chmoney,len);
strcpy(chmoney,"");
strncat(chmoney,ch1,len-1);
gotoxy(13,13);printf(" ");
}
gotoxy(13,13);printf("%s",chmoney);ch[0]=getch();
}
if((strlen(chshop)==0)||(strlen(chmoney)==0))
continue;
if((fp=fopen("home.dat","a+"))!=NULL);
fprintf(fp,"%10s%14s%6s",chtime,chshop,chmoney);
fputc('\n',fp);
fclose(fp);
i++;
gotoxy(41,5+i);
printf("%10s %-14s %-6s",chtime,chshop,chmoney);
}
}
}

二、萬年歷

#include"iostream.h"
#include"iomanip.h"
#include"stdlib.h"
leapyear(int a)/*是否是閏年*/
{
if((a%4==0&&a%100!=0)||(a%100==0&&a%400==0))
return (1);
else return (0);
}
int aa[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int cc[12]={31,29,31,30,31,30,31,31,30,31,30,31};
char bb[8][8]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
ww(int a,int b,int c)
{
int n=0,m=0,i,j,k=0;
for(i=1;i<c;i++)
{
if(leapyear(i)==1)
m=m+366;
else m=m+365;
}
for(j=1;j<b;j++)
{if(leapyear(c)==1) k=k+cc[j-1];
else k=k+aa[j-1];
}
n=(m+k+a)%7;
return n;
}
void yuefen(int m)
{
cout<<"最大天數是:";
if(m==2)
cout<<aa[m-1]+1;
else cout<<aa[m-1]<<endl;
}
void nianfen(int n)/*列印年份的日歷*/
{
int i,j,k;
if(leapyear(n)==1)
{
for(j=1;j<=12;j++)
{
cout<<j;
cout<<"月份"<<endl;
cout<<" 日"<<" 一"<<" 二"<<" 三"<<" 四"<<" 五"<<" 六"<<endl;
for(i=0;i<ww(1,j,n);i++)
{
cout<<setw(4)<<"";
}
for(k=1;k<=cc[j-1];k++)
{
cout<<setw(4)<<k;
if((ww(1,j,n)+k)%7==0)
cout<<endl;
}
cout<<endl;
}
}
else
{
for(j=1;j<=12;j++)
{
cout<<j;
cout<<"月份"<<endl;
cout<<ww(1,j,n)<<endl;
cout<<endl<<" 日"<<" 一"<<" 二"<<" 三"<<" 四"<<" 五"<<" 六"<<endl;
for(i=0;i<ww(1,j,n);i++)
{
cout<<setw(4)<<"";
}
for(k=1;k<=aa[j-1];k++)
{
cout<<setw(4)<<k;
if((ww(1,j,n)+k)%7==0)
cout<<endl;
}
cout<<endl;
}
}
}
void nianyue(int n,int y)/*列印某年某月的月歷*/
{
int i,k;
if(leapyear(n)==1)
{
cout<<" 日"<<" 一"<<" 二"<<" 三"<<" 四"<<" 五"<<" 六"<<endl;
for(i=0;i<ww(1,y,n);i++)
{
cout<<setw(4)<<"";
}
for(k=1;k<=cc[y-1];k++)
{
cout<<setw(4)<<k;
if((ww(1,y,n)+k)%7==0)
cout<<endl;
}
cout<<endl;
}
else
{ cout<<endl<<" 日"<<" 一"<<" 二"<<" 三"<<" 四"<<" 五"<<" 六"<<endl;
for(i=0;i<ww(1,y,n);i++)
{
cout<<setw(4)<<"";
}
for(k=1;k<=aa[y-1];k++)
{
cout<<setw(4)<<k;
if((ww(1,y,n)+k)%7==0)
cout<<endl;
}
cout<<endl;
}
}
void main()
{
int n,m;
int day,month ,year;
while(1)
{
cout<<"***********************************:"<<endl;
cout<<"1查詢某年某月某日是星期幾"<<endl
<<"2是否為閏年"<<endl
<<"3查詢某月的最大天數"<<endl
<<"4列印某年的全年日歷"<<endl
<<"5列印某年某月的月歷"<<endl
<<"6exit"<<endl
<<"***********************************:"<<endl;
cout<<"請輸入要操作的指令:"<<endl;
cin>>n;
switch(n)
{
case 1:cout<<"請輸入要查詢的日期:";
cout<<"year:";
cin>>year;
cout<<endl<<"month:";
cin>>month;
cout<<endl<<"day:";
cin>>day;
cout<<"星期是:";
cout<<bb[ww(day,month,year)]<<endl;break;
switch(ww(day,month,year))
{
case 1:cout<<"星期一";break;
case 2:cout<<"星期二";break;
case 3:cout<<"星期三";break;
case 4:cout<<"星期四";break;
case 5:cout<<"星期五";break;
case 6:cout<<"星期六";break;
case 7:cout<<"星期日";break;
}
cout<<endl;break;
case 2:cout<<"請輸入要查詢的年份:";
cin>>m;
if(leapyear(m)==1) cout<<"是閏年"<<endl;
else cout<<"不是閏年,請返回重新輸入"<<endl;
break;
case 3:cout<<"請輸入月份:";
cin>>m;
yuefen(m);break;
case 4:cout<<"請輸入所要列印年份:";
cin>>m;
nianfen(m);break;
case 5:cout<<"請輸入年份:";
cin>>n;
cout<<endl<<"請輸入月份:";
cin>>m;
cout<<endl;
nianyue(n,m);break;
case 6:exit(0);
}
}
}

『柒』 求C語言程序設計實例(200行)

時間函數舉常式序分析
2.程序源代碼:

#include "stdio.h"
#include "time.h"
void main()
{
time_t lt; /*define a longint time varible*/
lt=time(NULL);/*system time and date*/
printf(ctime(<)); /*english format output*/
printf(asctime(localtime(<)));/*tranfer to tm*/
printf(asctime(gmtime(<))); /*tranfer to Greenwich time*/
}
【程序92】

題目:時間函數舉例2

1.程序分析:

2.程序源代碼:

/*calculate time*/
#include "time.h"
#include "stdio.h"
main()
{
time_t start,end;
int i;
start=time(NULL);
for(i=0;i<3000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=time(NULL);
printf("\1: The different is %6.3f\n",difftime(end,start));
}
【程序93】

題目:時間函數舉例3

1.程序分析:

2.程序源代碼:

/*calculate time*/
#include "time.h"
#include "stdio.h"
main()
{
clock_t start,end;
int i;
double var;
start=clock();
for(i=0;i<10000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=clock();
printf("\1: The different is %6.3f\n",(double)(end-start));
}
【程序94】

題目:時間函數舉例4,一個猜數游戲,判斷一個人反應快慢。(版主初學時編的)

1.程序分析:

2.程序源代碼:

#include "time.h"
#include "stdlib.h"
#include "stdio.h"
main()
{
char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\nplease input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{
if(guess>i)
{
printf("please input a little smaller.\n");
scanf("%d",&guess);
}
else
{
printf("please input a little bigger.\n");
scanf("%d",&guess);
}
}
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congralations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
if((c=getch())=='y')
goto loop;
}
【程序95】

題目:家庭財務管理小程序

1.程序分析:

2.程序源代碼:

/*money management system*/
#include "stdio.h"
#include "dos.h"
main()
{
FILE *fp;
struct date d;
float sum,chm=0.0;
int len,i,j=0;
int c;
char ch[4]="",ch1[16]="",chtime[12]="",chshop[16],chmoney[8];
pp: clrscr();
sum=0.0;
gotoxy(1,1);printf("|----------------------------------------------------|");
gotoxy(1,2);printf("| money management system(C1.0) 2000.03 |");
gotoxy(1,3);printf("|----------------------------------------------------|");
gotoxy(1,4);printf("| -- money records -- | -- today cost list -- |");
gotoxy(1,5);printf("| ------------------------ |-----------------------------|");
gotoxy(1,6);printf("| date: -------------- | |");
gotoxy(1,7);printf("| | | | |");
gotoxy(1,8);printf("| -------------- | |");
gotoxy(1,9);printf("| thgs: ------------------ | |");
gotoxy(1,10);printf("| | | | |");
gotoxy(1,11);printf("| ------------------ | |");
gotoxy(1,12);printf("| cost: ---------- | |");
gotoxy(1,13);printf("| | | | |");
gotoxy(1,14);printf("| ---------- | |");
gotoxy(1,15);printf("| | |");
gotoxy(1,16);printf("| | |");
gotoxy(1,17);printf("| | |");
gotoxy(1,18);printf("| | |");
gotoxy(1,19);printf("| | |");
gotoxy(1,20);printf("| | |");
gotoxy(1,21);printf("| | |");
gotoxy(1,22);printf("| | |");
gotoxy(1,23);printf("|--------------------------------------------------|");
i=0;
getdate(&d);
sprintf(chtime,"%4d.%02d.%02d",d.da_year,d.da_mon,d.da_day);
for(;;)
{
gotoxy(3,24);printf(" Tab __browse cost list Esc __quit");
gotoxy(13,10);printf(" ");
gotoxy(13,13);printf(" ");
gotoxy(13,7);printf("%s",chtime);
j=18;
ch[0 ]=getch();
if(ch[0]==27)
break;
strcpy (chshop,"");
strcpy(chmoney,"");
if(ch[0]==9)
{
mm:i=0;
fp=fopen("home.dat","r+");
gotoxy(3,24);printf(" ");
gotoxy(6,4);printf(" list records ");
gotoxy(1,5);printf("|-------------------------------------|");
gotoxy(41,4);printf(" ");
gotoxy(41,5);printf(" |");
while(fscanf(fp,"%10s%14s%f\n",chtime,chshop,&chm)!=EOF)
{
if(i==36)
{
getch();
i=0;
}
if ((i%36)<17)
{
gotoxy(4,6+i);
printf(" ");
gotoxy(4,6+i);
}
else
if((i%36)>16)
{
gotoxy(41,4+i-17);
printf(" ");
gotoxy(42,4+i-17);
}
i++;
sum=sum+chm;
printf("%10s %-14s %6.1f\n",chtime,chshop,chm);}
gotoxy(1,23);printf("|----------------------------------------------|");
gotoxy(1,24);printf("| |");
gotoxy(1,25);printf("|----------------------------------------------|");
gotoxy(10,24);printf("total is %8.1f$",sum);
fclose(fp);
gotoxy(49,24);printf("press any key to.....");getch();goto pp;
}
else
{
while(ch[0]!='\r')
{
if(j<10)
{
strncat(chtime,ch,1);
j++;
}
if(ch[0]==8)
{
len=strlen(chtime)-1;
if(j>15)
{
len=len+1;
j=11;
}
strcpy(ch1,"");
j=j-2;
strncat(ch1,chtime,len);
strcpy(chtime,"");
strncat(chtime,ch1,len-1);
gotoxy(13,7);printf(" ");
}
gotoxy(13,7);printf("%s",chtime);ch[0]=getch();
if(ch[0]==9)
goto mm;
if(ch[0]==27)
exit(1);
}
gotoxy(3,24);printf(" ");
gotoxy(13,10);
j=0;
ch[0]=getch();
while(ch[0]!='\r')
{
if (j<14)
{
strncat(chshop,ch,1);
j++;
}
if(ch[0]==8)
{
len=strlen(chshop)-1;
strcpy(ch1,"");
j=j-2;
strncat(ch1,chshop,len);
strcpy(chshop,"");
strncat(chshop,ch1,len-1);
gotoxy(13,10);printf(" ");
}
gotoxy(13,10);printf("%s",chshop);ch[0]=getch();}
gotoxy(13,13);
j=0;
ch[0]=getch();
while(ch[0]!='\r')
{
if (j<6)
{
strncat(chmoney,ch,1);
j++;
}
if(ch[0]==8)
{
len=strlen(chmoney)-1;
strcpy(ch1,"");
j=j-2;
strncat(ch1,chmoney,len);
strcpy(chmoney,"");
strncat(chmoney,ch1,len-1);
gotoxy(13,13);printf(" ");
}
gotoxy(13,13);printf("%s",chmoney);ch[0]=getch();
}
if((strlen(chshop)==0)||(strlen(chmoney)==0))
continue;
if((fp=fopen("home.dat","a+"))!=NULL);
fprintf(fp,"%10s%14s%6s",chtime,chshop,chmoney);
fputc('\n',fp);
fclose(fp);
i++;
gotoxy(41,5+i);
printf("%10s %-14s %-6s",chtime,chshop,chmoney);
}
}
}

【程序96】

題目:計算字元串中子串出現的次數

1.程序分析:

2.程序源代碼:

#include "string.h"
#include "stdio.h"
main()
{
char str1[20],str2[20],*p1,*p2;
int sum=0;
printf("please input two strings\n");
scanf("%s%s",str1,str2);
p1=str1;p2=str2;
while(*p1!='\0')
{
if(*p1==*p2)
{
while(*p1==*p2&&*p2!='\0')
{
p1++;
p2++;
}
}
else
p1++ ;
if(*p2=='\0')
sum++;
p2=str2;
}
printf("%d",sum);
getch();
}
【程序97】

題目:從鍵盤輸入一些字元,逐個把它們送到磁碟上去,直到輸入一個#為止。

1.程序分析:

2.程序源代碼:

#include "stdio.h"
main()
{
FILE *fp;
char ch,filename[10];
scanf("%s",filename);
if((fp=fopen(filename,"w"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
ch=getchar();
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);putchar(ch);
ch=getchar();
}
fclose(fp);
}

【程序98】

題目:從鍵盤輸入一個字元串,將小寫字母全部轉換成大寫字母,然後輸出到一個磁碟文件"test"中保存。輸入的字元串以!結束。

1.程序分析:

2.程序源代碼:

#include "stdio.h"
main()
{
FILE *fp;
char str[100],filename[10];
int i=0;
if((fp=fopen("test","w"))==NULL)
{
printf("cannot open the file\n");
exit(0);
}
printf("please input a string:\n");
gets(str);
while(str[i]!='!')
{
if(str[i]>='a'&&str[i]<='z')
str[i]=str[i]-32;
fputc(str[i],fp);
i++;
}
fclose(fp);
fp=fopen("test","r");
fgets(str,strlen(str)+1,fp);
printf("%s\n",str);
fclose(fp);
}
【程序99】

題目:有兩個磁碟文件A和B,各存放一行字母,要求把這兩個文件中的信息合並(按字母順序排列),
輸出到一個新文件C中。

1.程序分析:

2.程序源代碼:

#include "stdio.h"
main()
{
FILE *fp;
int i,j,n,ni;
char c[160],t,ch;
if((fp=fopen("A","r"))==NULL)
{
printf("file A cannot be opened\n");
exit(0);
}
printf("\n A contents are :\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]);
}
fclose(fp);
ni=i;
if((fp=fopen("B","r"))==NULL)
{
printf("file B cannot be opened\n");
exit(0);
}
printf("\n B contents are :\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]);
}
fclose(fp);
n=i;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(c[i]>c[j])
{
t=c[i];c[i]=c[j];c[j]=t;
}
printf("\n C file is:\n");
fp=fopen("C","w");
for(i=0;i<n;i++)
{
putc(c[i],fp);
putchar(c[i]);
}
fclose(fp);
}
【程序100】

題目:有五個學生,每個學生有3門課的成績,從鍵盤輸入以上數據(包括學生號,姓名,三門課成績),計算出平均成績,況原有的數據和計算出的平均分數存放在磁碟文件"stud"中。

1.程序分析:

2.程序源代碼:

#include "stdio.h"
struct student
{
char num[6];
char name[8];
int score[3];
float avr;
} stu[5];
main()
{
int i,j,sum;
FILE *fp;
/*input*/
for(i=0;i<5;i++)
{
printf("\n please input No. %d score:\n",i);
printf("stuNo:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
sum=0;
for(j=0;j<3;j++)
{
printf("score %d.",j+1);
scanf("%d",&stu[i].score[j]);
sum+=stu[i].score[j];
}
stu[i].avr=sum/3.0;
}
fp=fopen("stud","w");
for(i=0;i<5;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}

『捌』 高分求一個200行左右的C語言程序要簡單的我才學C語言

//C語言代碼
#include <stdio.h>
void main()
{
printf("hello!");//此行復制200遍即可
}

『玖』 C語言課程設計不少於200行代碼

#include "stdio.h"
#include"stdlib.h"
#include "conio.h"
#include"string.h"
struct SStudent
{
unsigned number;
char name[10];
char tele[12];
struct SStudent * link;
};
void main()
{
struct SStudent * CreateTable();
void AppendToTable(struct SStudent * stu);
void InsertToTable(struct SStudent * stu);
void QueryTable(struct SStudent * stu, unsigned number);
void SortTable(struct SStudent * stu);
void PrintTable(struct SStudent * stu);
void Save(struct SStudent * stu);
void Load(struct SStudent * stu);
void Help();
void modi(struct SStudent *h);
void search(struct SStudent *h);struct SStudent * student;
unsigned number;
char keyValue;
student = CreateTable();
//clrscr();
system("cls");
Help();
printf("\n= ");
while((keyValue = getche()) != 'q' && keyValue != 'Q' && keyValue != 27)
{
puts("");
switch(keyValue)
{
case 'l': case 'L':
PrintTable(student); break;
case 'd': case 'D':
printf("Please input the number you want delete: ");
scanf("%d", &number);
QueryTable(student, number);
break;
case 'a': case 'A':
AppendToTable(student); break;
case 'i': case 'I':
InsertToTable(student); break;
case 's': case 'S':
SortTable(student);
puts("Sort complished! Please use command L to list.");
break;
case 'f': case 'F':
search(student);
break;
case 'm': case 'M':
modi(student);
break;case 'v': case 'V':
Save(student); break;
case 'o': case 'O':
Load(student); break;
case 'h': case 'H':
Help(); break;
default: puts("Error command!");
}
printf("\n= ");
}
}
struct SStudent * CreateTable()
{
struct SStudent * stu;
stu = (struct SStudent *) malloc(sizeof(struct SStudent));
stu->number = 0;
stu->name[0] = '\0';
stu->tele[0] = '\0';
stu->link = NULL;
return(stu);
}
void AppendToTable(struct SStudent * stu)
{
struct SStudent * next, * last;
int number;
last = stu;
while(last->link) last = last->link;
printf("Please input the number (0 to quit): ");
scanf("%d", &number);
while(number)
{
next = (struct SStudent *) malloc(sizeof(struct SStudent));
next->number = number;
printf("Please input name: ");
scanf("%s", next->name);
printf("Please input tele: ");
scanf("%s", next->tele);
last->link = next;
last = last->link;
printf("\nPlease input the number (0 to quit): ");
scanf("%d", &number);
}
last->link = NULL;
}
void InsertToTable(struct SStudent * stu)
{
struct SStudent * next, * last;
int number;
printf("Please input the number (0 to quit): ");
scanf("%d", &number);
while(number)
{
next = (struct SStudent *) malloc(sizeof(struct SStudent));
next->number = number;
printf("Please input name: ");
scanf("%s", next->name);
printf("Please input tele: ");
scanf("%s", next->tele);
last = stu;
while(last->link)
{
if(last->link->number > next->number)
{
next->link = last->link;
last->link = next;
break;
}
else last = last->link;
}
printf("\nPlease input the number (0 to quit): ");
scanf("%d", &number);
}
}
void QueryTable(struct SStudent * stu, unsigned number)
{
struct SStudent * temp, * next;
next = stu;
while(next->link)
{
if(next->link->number == number)
{
temp = next->link;
next->link = next->link->link;
free(temp);
}
else next = next->link;
}
}
void PrintTable(struct SStudent * stu)
{
stu = stu->link;
if(!stu)
{
puts("The table is EMPTY!");
return;
}
printf("number\tname\ttele\n");
while(stu)
{
printf("%3d\t", stu->number);
printf("%-s\t", stu->name);
printf("%-s\t", stu->tele);
printf("\n");
stu = stu->link;
}
}
void SortTable(struct SStudent * stu)
{
struct SStudent * next, * last, * temp;
int flag;
last = stu;
while(last->link)
{
next = stu; flag = 1;
while(next->link != last->link)
{
if(next->link->number > last->link->number)
{
temp = last->link;
last->link = last->link->link;
temp->link = next->link;
next->link = temp;
flag = 0;
break;
}
else next = next->link;
}
if(flag) last = last->link;
}
}
void Save(struct SStudent * stu)
{
char filename[13];
FILE * fileSave;
printf("Please input the filename you want save in: ");
scanf("%s", filename);
if((fileSave = fopen(filename, "wb")) == 0)
{
printf("Cannot open file %s !\n", filename);
return;
}
puts("Saveing ...");
stu = stu->link;
while(stu)
{
fwrite(stu, sizeof(struct SStudent), 1, fileSave);
stu = stu->link;
}
puts("Saveing is finished!");
}
void Load(struct SStudent * stu)
{char filename[13];<br>FILE * fileLoad;<br>struct SStudent * temp;<br>while(stu->link)<br>{<br>temp = stu->link;<br>stu->link = stu->link->link;<br>free(temp);<br>}
temp = (struct SStudent *) malloc(sizeof(struct SStudent));
printf("Please input the filename you want load from: ");
scanf("%s", filename);
if((fileLoad = fopen(filename, "rb")) == 0)
{
printf("Cannot open file %s !\n", filename);
return;
}
puts("Loading ...");
while(fread(temp, sizeof(struct SStudent), 1, fileLoad))
{stu->link = temp;<br>stu = stu->link;<br>temp = (struct SStudent *) malloc(sizeof(struct SStudent));<br>}
stu->link = NULL;
puts("loading is finished!");
}
void Help()
{ puts(" *********************************************");
puts(" * System Command Help *");
puts(" *********************************************");
puts(" * L = List all records *");
puts(" * D = Delete a record seleced by number *");
puts(" * A = Append records *");
puts(" * I = Insert records *");
puts(" * S = Sort records *");
puts(" * F= Search records *");
puts(" * M= Modi records *");puts(" * H = Show this help message *");
puts(" * V = Save records to a file *");
puts(" * O = Load records from a file *");
puts(" * Q = Quit System *");
puts(" *********************************************");
}
void modi(struct SStudent *h)
{
struct SStudent *p; /* 移動指針*/
unsigned num; /*存放學號的變數*/
// clrscr(); /*清屏幕*/
system("cls");
printf("please enter number for modifi\n");
scanf("%d",&num); /*輸入學號*/
p=h; /*將頭指針賦給p*/
while( (p->number!=num)&&p!=NULL) /*當記錄的姓名不是要找的,且指針不為空時*/
p=p->link; /*移動指針,指向下一結點*/
if(p==NULL) /*如果指針為空*/
printf("\nlist no %d student\n",num); /*顯示沒有該學生*/
else /*修改找到的記錄信息*/
{
printf("Please input new name: ");
scanf("%s", p->name);
printf("Please input new tele: ");
scanf("%s", p->tele);
printf("|number | name | tel | \n");
printf("|----------|---------------|---------------|\n");
printf("|%6d|%-10s|%12s|\n", p->number,p->name,p->tele); }
}
void search(struct SStudent *h)
{
struct SStudent *p; /* 移動指針*/
char s[10]; /*存放姓名的字元數組*/
// clrscr(); /*清屏幕*/
system("cls");
printf("please enter name for search\n");
scanf("%s",s); /*輸入姓名*/
p=h; /*將頭指針賦給p*/
while(strcmp(p->name,s)&&p!=NULL) /*當記錄的姓名不是要找的,且指針不為空時*/
p=p->link; /*移動指針,指向下一結點*/
if(p==NULL) /*如果指針為空*/
printf("\nlist no %s student\n",s); /*顯示沒有該學生*/
else /*顯示找到的記錄信息*/
{
printf("\n\n***********************havefound***********************\n");
printf("|number | name | tel | \n");
printf("|----------|---------------|---------------|\n");
printf("|%10d|%-10s|%12s|\n", p->number,p->name,p->tele);
printf("****************************end***************************\n");
}
}

『拾』 求大一C語言課程設計200行的程序

C語言編寫的迷宮小游戲 源代碼

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#define N 20/*迷宮的大小,可改變*/
int oldmap[N][N];/*遞歸用的數組,用全局變數節約時間*/
int yes=0;/*yes是判斷是否找到路的標志,1找到,0沒找到*/
int way[100][2],wayn=0;/*way數組是顯示路線用的,wayn是統計走了幾個格子*/
void Init(void);/*圖形初始化*/
void Close(void);/*圖形關閉*/
void DrawPeople(int *x,int *y,int n);/*畫人工探索物圖*/
void PeopleFind(int (*x)[N]);/*人工探索*/
void WayCopy(int (*x)[N],int (*y)[N]);/*為了8個方向的遞歸,把舊迷宮圖拷貝給新數組*/
int FindWay(int (*x)[N],int i,int j);/*自動探索函數*/
void MapRand(int (*x)[N]);/*隨機生成迷宮函數*/
void PrMap(int (*x)[N]);/*輸出迷宮圖函數*/
void Result(void);/*輸出結果處理*/
void Find(void);/*成功處理*/
void NotFind(void);/*失敗處理*/
void main(void)/*主函數*/
{
int map[N][N]; /*迷宮數組*/
char ch;
clrscr();
printf("\n Please select hand(1) else auto\n");/*選擇探索方式*/
scanf("%c",&ch);
Init(); /*初始化*/
MapRand(map);/*生成迷宮*/
PrMap(map);/*顯示迷宮圖*/
if(ch=='1')
PeopleFind(map);/*人工探索*/
else
FindWay(map,1,1);/*系統自動從下標1,1的地方開始探索*/
Result();/*輸出結果*/
Close();
}
void Init(void)/*圖形初始化*/
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
}
void DrawPeople(int *x,int *y,int n)/*畫人工控制圖*/
{/*如果將以下兩句注釋掉,則顯示人工走過的路徑,*/
setfillstyle(SOLID_FILL,WHITE); /*設置白色實體填充樣式*/
bar(100+(*y)*15-6,50+(*x)*15-6,100+(*y)*15+6,50+(*x)*15+6);
/*恢復原通路*/
switch(n)/*判斷x,y的變化,8個方向的變化*/
{
case 1: (*x)--;break; /*上*/
case 2: (*x)--;(*y)++;break ;/*右上*/
case 3: (*y)++;break; /*右*/
case 4: (*x)++;(*y)++;break; /*右下*/
case 5: (*x)++;break; /*下*/
case 6: (*x)++;(*y)--;break; /*左下*/
case 7: (*y)--;break; /*左*/
case 8: (*x)--;(*y)--;break; /*左上*/
}
setfillstyle(SOLID_FILL,RED);/*新位置顯示探索物*/
bar(100+(*y)*15-6,50+(*x)*15-6,100+(*y)*15+6,50+(*x)*15+6);
}
void PeopleFind(int (*map)[N])/*人工手動查找*/
{
int x,y;
char c=0;/*接收按鍵的變數*/
x=y=1;/*人工查找的初始位置*/
setcolor(11);
line(500,200,550,200);
outtextxy(570,197,"d");
line(500,200,450,200);
outtextxy(430,197,"a");
line(500,200,500,150);
outtextxy(497,130,"w");
line(500,200,500,250);
outtextxy(497,270,"x");
line(500,200,450,150);
outtextxy(445,130,"q");
line(500,200,550,150);
outtextxy(550,130,"e");
line(500,200,450,250);
outtextxy(445,270,"z");
line(500,200,550,250);
outtextxy(550,270,"c");/*以上是畫8個方向的控制介紹*/
setcolor(YELLOW);
outtextxy(420,290,"Press 'Enter' to end");/*壓回車鍵結束*/
setfillstyle(SOLID_FILL,RED);
bar(100+y*15-6,50+x*15-6,100+y*15+6,50+x*15+6);/*入口位置顯示*/
while(c!=13)/*如果按下的不是回車鍵*/
{
c=getch();/*接收字元後開始各個方向的探索*/
if(c=='w'&&map[x-1][y]!=1)
DrawPeople(&x,&y,1);/*上*/
else
if(c=='e'&&map[x-1][y+1]!=1)
DrawPeople(&x,&y,2);/*右上*/
else
if(c=='d'&&map[x][y+1]!=1)
DrawPeople(&x,&y,3);/*右*/
else
if(c=='c'&&map[x+1][y+1]!=1)
DrawPeople(&x,&y,4);/*右下*/
else
if(c=='x'&&map[x+1][y]!=1)
DrawPeople(&x,&y,5);/*下*/
else
if(c=='z'&&map[x+1][y-1]!=1)
DrawPeople(&x,&y,6); /*左下*/
else
if(c=='a'&&map[x][y-1]!=1)
DrawPeople(&x,&y,7); /*左*/
else if(c=='q'&&map[x-1][y-1]!=1)
DrawPeople(&x,&y,8); /*左上*/
}
setfillstyle(SOLID_FILL,WHITE); /*消去紅色探索物,恢復原迷宮圖*/
bar(100+y*15-6,50+x*15-6,100+y*15+6,50+x*15+6);
if(x==N-2&&y==N-2)/*人工控制找成功的話*/
yes=1; /*如果成功標志為1*/
}
void WayCopy(int (*oldmap)[N],int (*map)[N])/*拷貝迷宮數組 */
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
oldmap[i][j]=map[i][j];
}
int FindWay(int (*map)[N],int i,int j)/*遞歸找路*/
{
if(i==N-2&&j==N-2)/*走到出口*/
{
yes=1;/*標志為1,表示成功*/
return;
}
map[i][j]=1;/*走過的地方變為1*/
WayCopy(oldmap,map); /*拷貝迷宮圖*/
if(oldmap[i+1][j+1]==0&&!yes)/*判斷右下方是否可走*/
{
FindWay(oldmap,i+1,j+1);
if(yes)/*如果到達出口了,再把值賦給顯示路線的way數組,也正是這個原因,所以具體路線是從最後開始保存*/
{
way[wayn][0]=i;
way[wayn++][1]=j;
return;
}
}
WayCopy(oldmap,map);
if(oldmap[i+1][j]==0&&!yes)/*判斷下方是否可以走,如果標志yes已經是1也不用找下去了*/
{
FindWay(oldmap,i+1,j);
if(yes)
{
way[wayn][0]=i;
way[wayn++][1]=j;
return;
}
}
WayCopy(oldmap,map);
if(oldmap[i][j+1]==0&&!yes)/*判斷右方是否可以走*/
{
FindWay(oldmap,i,j+1);
if(yes)
{
way[wayn][0]=i;
way[wayn++][1]=j;
return;
}
}
WayCopy(oldmap,map);
if(oldmap[i-1][j]==0&&!yes)/*判斷上方是否可以走*/
{
FindWay(oldmap,i-1,j);
if(yes)
{
way[wayn][0]=i;
way[wayn++][1]=j;
return;
}
}
WayCopy(oldmap,map);
if(oldmap[i-1][j+1]==0&&!yes)/*判斷右上方是否可以走*/
{
FindWay(oldmap,i-1,j+1);
if(yes)
{
way[wayn][0]=i;
way[wayn++][1]=j;
return;
}
}
WayCopy(oldmap,map);
if(oldmap[i+1][j-1]==0&&!yes)/*判斷左下方是否可以走*/
{
FindWay(oldmap,i+1,j-1);
if(yes)
{
way[wayn][0]=i;
way[wayn++][1]=j;
return;
}
}
WayCopy(oldmap,map);
if(oldmap[i][j-1]==0&&!yes)/*判斷左方是否可以走*/
{
FindWay(oldmap,i,j-1);
if(yes)
{
way[wayn][0]=i;
way[wayn++][1]=j;
return;
}
}
WayCopy(oldmap,map);
if(oldmap[i-1][j-1]==0&&!yes)/*判斷左上方是否可以走*/
{
FindWay(oldmap,i-1,j-1);
if(yes)
{
way[wayn][0]=i;
way[wayn++][1]=j;
return;
}
}
return;
}
void MapRand(int (*map)[N])/*開始的隨機迷宮圖*/
{
int i,j;
cleardevice();/*清屏*/
randomize(); /*隨機數發生器*/
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
if(i==0||i==N-1||j==0||j==N-1)/*最外面一圈為牆壁*/
map[i][j]=1;
else
if(i==1&&j==1||i==N-2&&j==N-2)/*出發點與終點表示為可走的*/
map[i][j]=0;
else
map[i][j]=random(2);/*其它的隨機生成0或1*/
}
}
}
void PrMap(int (*map)[N])/*輸出迷宮圖*/
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
if(map[i][j]==0)
{
setfillstyle(SOLID_FILL,WHITE);/*白色為可走的路*/
bar(100+j*15-6,50+i*15-6,100+j*15+6,50+i*15+6);
}
else
{
setfillstyle(SOLID_FILL,BLUE);/*藍色為牆壁*/
bar(100+j*15-6,50+i*15-6,100+j*15+6,50+i*15+6);
}
}
void Find(void)/*找到通路*/
{
int i;
setfillstyle(SOLID_FILL,RED);/*紅色輸出走的具體路線*/
wayn--;
for(i=wayn;i>=0;i--)
{
bar(100+way[i][1]*15-6,50+way[i][0]*15-6,100+
way[i][1]*15+6,50+way[i][0]*15+6);
sleep(1);/*控制顯示時間*/
}
bar(100+(N-2)*15-6,50+(N-2)*15-6,100+
(N-2)*15+6,50+(N-2)*15+6); /*在目標點標紅色*/
setcolor(GREEN);
settextstyle(0,0,2);/*設置字體大小*/
outtextxy(130,400,"Find a way!");
}
void NotFind(void)/*沒找到通路*/
{
setcolor(GREEN);
settextstyle(0,0,2);/*設置字體大小*/
outtextxy(130,400,"Not find a way!");
}
void Result(void)/*結果處理*/
{
if(yes)/*如果找到*/
Find();
else/*沒找到路*/
NotFind();
getch();
}
void Close(void)/*圖形關閉*/
{
closegraph();
}