当前位置:首页 » 编程语言 » 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();
}