c语言函数程序设计50行 c语言函数编写程序

谁帮我写一个50行的C语言代码啊~#includestdio.h
#includestdlib.h
int next[50];//存储next值的数组
int nextval[50];
typedef struct
{
char *ch;
int length;//串长度
}HString;
void StrAssign(HString *T,char *chars) //生成一个值等于串常量chars的串T
{
int i,j;
char *c;
if(T-ch)
free(T-ch);//释放T原有空间
for(i=0,c=chars; *c;i,c) //求chars长度
;
if(!i)
{
T-ch = NULL;
T-length = 0;
}
else
{
if(!(T-ch=(char*)malloc((i 1)*sizeof(char))))
exit(1);
for(j=0;ji;j)
T-ch[j] = chars[j];
T-ch[i] = '\0';
T-length = i;
}
}
int StrLength(HString s) //返回S的元素个数,称串的长度
{
return s.length;
}
int StrCompare(HString S,HString T) //串比较
{
//若ST,则返回值0;若S=T,则返回值=0,若ST,则返回值0;
int i;
for(i=0; iS.lengthiT.length;i)
if(S.ch[i]!=T.ch[i])
return S.ch[i] - T.ch[i];
return S.length - T.length;
}
void ClearString(HString *S)//将S清为空串
{
if(S-ch)
{
free(S-ch);
S-ch = NULL;
}
S-length = 0;
}
void Concat(HString *T,HString s1,HString s2)
{
//用T返回由s1,s2联接而成的新串
int i,j;
if(T-ch) free(T-ch);//释放旧空间
if(!(T-ch=(char*)malloc((s1.length s2.length)*sizeof(char))))
exit(1);
T-length = s1.lengths2.length;
for(i=0;is1.length;i)
T-ch[i] = s1.ch[i];
for(j=0;js2.length;j,i)
T-ch[i] = s2.ch[j];
}
void SubString(HString *sub,HString s,int pos,int len)
{
//用sub返回串s的第pos个字符起长度为len的子串
//其中,1=pos=strlenth(s)且0=len=strlength(s)-pos1.
int i,j;
if(pos1 || poss.length || len0 || lens.length-pos 1)
{
printf("SubString's Location error!\n");
exit(1);
}
if(sub-ch) free(sub-ch); //释放旧空间
if(!len)
{
sub-ch = NULL; sub-length = 0;
}
else
{
sub-ch = (char*)malloc((len 1)*sizeof(char));
for(i=0,j=pos-1;j=pos len-2;i,j)
sub-ch[i] = s.ch[j];
sub-length = len;
sub-ch[sub-length] = '\0';
}
}
void get_next(char *chars,int next[]) //生成next值的函数
{
int i,j,temp;
i = 1;
j = 0;
next[1] = 0;
while(chars[i])
{
if(j==0i==1)//第二位的next应该都为1
{
i;j;
next[i] = j;
}
else if(chars[i-1]!=chars[next[i]-1])//当测试next值上的数据与当前数据不等时进行
{
j = next[i];//取得next值
while(chars[j-1]!=chars[i-1]) //如当前的值,与下一next值也不同 , j值继续后退
{
temp = j;//取得前一next值
j = next[j]; //前一next值
if(j=0)
{
next[i 1] = 1;
i;
break;
}
else if(chars[j-1]==chars[i-1])
{
next[i 1] = next[temp]1;//这里temp与J总是相隔一个位,所以是next[temp]
i;
break;
}
}
}
else if(chars[i-1]==chars[next[i]-1]) //当测试next值上的数据与当前数据相等时进行
{
next[i 1] = next[i]1;
i;
}
printf("next[%d]=%d\n",i,next[i]);
}
}
void next_change(char *chars,int nextval[])
{
int i,j,temp;
i = 1;
nextval[1] = 0;
for(j=1;chars[j];j)
{
temp = next[j 1]; //取得当前的next[X]值
if(chars[j]==chars[temp-1]) //比较J位置上与相对于J位置的NEXT位上的元素值是否相等
{
nextval[j 1] = nextval[temp]; //如相等则将前面的nextval值赋给当前nextval的值
}
else nextval[j 1] = temp;//不相等则保留原next[]中的值
}
}
int Index(HString S,HString T,int pos)
{
int i,j;
i = pos-1;
j = 0;
get_next(T.ch,next);
next_change(T.ch,nextval);
while(i=S.lengthT.ch[j]) //字符串没到结尾不结束查找
{
if(S.ch[i]==T.ch[j])//相等则一起后移
{
i;j;
}
else if(S.ch[i]!=T.ch[j])
{
j = nextval[j 1]-1;//不相等时取得next值-1因为
//next是按1,2,3...算所以要-1
if(j=0S.ch[i]!=T.ch[j])
{
i;//J移到next值上如值是0则i向前移
j = 0;//因为j可以变成小于0
}
}
}
if(j=T.length) return i-T.length 1;
else return 0;
}
void StrInsert(HString *s,int pos,HString T) //在pos位置插入字符串T
{
int i,j;
if(pos1 || pos(s-length 1))
{
printf("strInsert's Location error!\n");
exit(1);
}
if(T.length)
s-ch = (char*)realloc(s-ch,(s-length T.length 1)*sizeof(char)); //增加S的空间
for(j=s-length;j=pos-1;--j)//POS位置到最后的字符往后移
s-ch[j T.length] = s-ch[j];
for(i=0;iT.length;i)//T复制到S
{
s-ch[i pos-1] = T.ch[i];
}
s-length = s-lengthT.length;
}
void StrDelete(HString *s,int pos,int len)//S存在,从S中删除第POS个字符起长度为LEN的子串
{
int i,j;
if(pos1 || poss-length-len)//判断删除位置是否合理
printf("delete Location error!\n");
else
{
for(i=pos len-1,j=0;is-length;i,j)//删除中间元素,后面的元素往前移
s-ch[pos-1 j] = s-ch[i];
s-length = s-length - len;
s-ch[s-length] = '\0';
}
}
void Replace(HString *s,HString t,HString v) //将V替换掉S中的T
{
int i;
i = Index(*s,t,1);
while(i0)
{
StrDelete(s,i,t.length);
StrInsert(s,i,v);
i = Index(*s,t,1);
}
}
void display(HString s)
{
printf("the string is :%s\n",s.ch);
}
int main(void)
{
HString obj,obj2,obj3,obj4;
obj.ch = NULL;//(char*)malloc(sizeof(char));
obj2.ch = NULL;
obj3.ch = NULL;
obj4.ch = NULL;
StrAssign(obj,"august");
StrAssign(obj2,"yx");
StrAssign(obj4,"ax");
display(obj);
display(obj2);
SubString(obj3,obj,3,3);
display(obj3);
StrInsert(obj3,1,obj2);
display(obj3);
Replace(obj3,obj2,obj4);
display(obj3);
StrDelete(obj3,1,3);
display(obj3);
return 0;
}
//希望能够帮到你
c语言程序设计自定义函数最少50行,刚刚入门简单点啊 , 老大们你要50行我就把他编的多一点
#includestdio.h
int main()
{
void yearplus(int y,int m,int d);
void yearreduce(int y,int m,int d);
void year1949(int m,int d);
int year,month,day;
char c1,c2;
printf("请输入一个日期 , 格式为yyyy-M-d:");
scanf("%d%c%d%c%d",year,c1,month,c2,day);
if(year1949)yearplus(year,month,day);
if(year1949)yearreduce(year,month,day);
if(year==1949)year1949(month,day);
return 0;
}
void yearplus(int y,int m, int d)
{
int yt,sum=0;
int switchf(int m,int d);
for(yt=1950;yt=y;yt)
{
if((yt%4==0yt0!=0)||yt@0==0)//扫描年
sum =366;
else sum =365;
}
sum =(switchf(m,d) 91);
if(((y%4==0y0!=0)||y@0==0)m=2)
sum =1;
printf("%d\n",sum);
}
void yearreduce(int y,int m,int d)
{
int yt,sum=0;
int switchf(int m,int d);
for(yt=y 1;yt1949;yt)
{
if((yt%4==0yt0!=0)||yt@0==0)//扫描年
sum =366;
else sum =365;
}
sum =273;
if(((y%4==0y0!=0)||y@0==0)m2)
sum=(366-switchf(m,d)-1) sum;
if(((y%4==0y0!=0)||y@0==0)m2)
sum=(366-switchf(m,d)) sum;
printf("%d\n",sum);
}
void year1949(int m,int d)
{
int sum=0;
if(m10)
sum=273-switchf(m,d);
if(m10)
sum=switchf(m,d)-274;
if(m==10)
{
if(d==1)sum=0;
if(d1)sum=d-1;
}
printf("%d\n",sum);
}
int switchf(int m,int d)
{
int sum=0;
switch(m)
{
case 1: sum =0 d;break;
case 2: sum =31 d;break;
case 3: sum =59 d;break;
case 4: sum =90 d;break;
case 5:sum =120 d;break;
case 6:sum =151 d;break;
case 7:sum =181 d;break;
case 8:sum =212 d;break;
case 9:sum =243 d;break;
case 10:sum =273 d;break;
case 11:sum =304 d;break;
case 12:sum =334 d;break;
}
return sum;
}
给几个50行左右简单的C语言程序设计谢谢~~#includestdio.h
#define max 100
int helix(int a,int b,int e,int f,int s[max][max])
{int i;
static int c=1;
for(i=1;i=e;i)
s[a][b]=c;
f--;
a--;
if(f!=0)
{
for(i=1;i=f;i)
s[a][b]=c;
e--;
if(e!=0)
{for(i=1;i=e;i)
s[--a][b]=c;
f--;
if(f!=0)
for(i=1;i=f;i)
s[a][--b]=c;
}
}
}
main()
{int m,n,x,y,i=1,j,c,t,s[max][max];
printf("please input the hanglie number.");
scanf("%d %d %d \n",m,n,t);
x=m;
y=n;
while(1)
{ helix(i,i,x,y,s);
x=x-2;
y=y-2;
if(x=0||y=0)
break;
i;
}
printf("\n");
if(t==0)
{for(i=1;i=m;i)
{for(j=1;j=n;j)
printf("%d",s[i][j]);
printf("\n");
}
}
else
{for(i=1;i=n;i)
{for(j=1;j=m;j)
printf("%d",s[j][i]);
printf("\n");
}
}
getch();
}
数字的逆序输出,自己尝试著编译看看
求50行简单C语言程序代码,基础的就好#include stdio.h
#include stdlib.h
#define NUM 10
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//冒泡排序算法
//基本思想:比较相邻的两个数,如果前者比后者大,则进行交换 。每一轮排序结束,选出一个未排序中最大的数放到数组后面 。
void bubbleSort(int *arr, int n) {
int i,j;
for (i = 0; in - 1; i)
for (j = 0; jn - i - 1; j) {
//如果前面的数比后面大,进行交换
if (arr[j]arr[j1]) {
【c语言函数程序设计50行 c语言函数编写程序】int temp = arr[j];
arr[j] = arr[j1];
arr[j1] = temp;
}
}
}
//最差时间复杂度为O(n^2),平均时间复杂度为O(n^2) 。稳定性:稳定 。辅助空间O(1) 。
//升级版冒泡排序法:通过从低到高选出最大的数放到后面 , 再从高到低选出最小的数放到前面,
//如此反复,直到左边界和右边界重合 。当数组中有已排序好的数时,这种排序比传统冒泡排序性能稍好 。
//升级版冒泡排序算法
void bubbleSort_1(int *arr, int n) {
//设置数组左右边界
int left = 0, right = n - 1;
//当左右边界未重合时,进行排序
while (left=right) {
int i,j;
//从左到右遍历选出最大的数放到数组右边
for (i =left; iright; i) {
if (arr[i]arr[i1]) {
int temp = arr[i];
arr[i] = arr[i1];
arr[i1] = temp;
}
}
right--;
//从右到左遍历选出最小的数放到数组左边
for (j = right; j left; j--) {
if (arr[j1]arr[j]) {
int temp = arr[j];
arr[j] = arr[j1];
arr[j1] = temp;
}
}
left;
}
}
int main(int argc, char *argv[]) {
int arr[NUM],i,j,temp;
printf("请输入10个数:\n");
for(i=0; iNUM; i) {
printf("请输入第(%d)个数:",i 1);
scanf("%d",arr[i]);
}
printf("\n输入如下排列:\n");
for(i=0; iNUM; i) {
printf("M",arr[i]);
}/*
for(i=0; iNUM; i) {
for(j=i 1; jNUM; j) {
if(arr[i]arr[j]) {
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}*/
bubbleSort_1(arr,NUM);
/*printf("\n从小到大如下排列:\n");
for(i=0; iNUM; i) {
printf("M",arr[i]);
}*/
printf("\n从大到小如下排列:\n");
for(i=NUM-1; i=0; i--) {
printf("M",arr[i]);
}
return 0;
}
求一个50行左右的C语言编程 。这是一个玩五子棋的例子:
#include iostream.h
#include process.h
#include conio.h
class five
{
int x;
int y;
int m;
int n;
int num_xy;
int num_mn;
char qipan[20][20];
public:
five(int X = 0,int Y =0,int M = 0,int N = 0,int Num_xy = 0,int Num_mn = 0)
{
x = X;
y = Y;
m = M;
n = N;
num_xy = Num_xy;
num_mn = Num_mn;
for(int i = 0 ; i20 ; i)
{
for(int j = 0 ;j20 ; j)
qipan[i][j] = '.';
}
}
int getm()
{
return m;
}
int getn()
{
return n;
}
void getpointxy();
void getpointmn();
void machinemn();
void showqipan();
void print();
bool IsxyWin();
bool IsmnWin();
int dangerlevel(int a,int b);
void attack();
};
void five::getpointxy()
{
cout"请分别输入第"num_xy 1"步白棋('o')的横坐标和纵坐标:";
cinxy;
if(x = 0 || y = 0 || x20 || y20 )
{
cout"出界 , 请重新输入:"endl ;
getpointxy();
}
else if(qipan[y-1][x-1] != '.' )
{
cout"请所下的位置已经有棋子,请重新输入:" endl;
getpointxy();
}
else if(num_xy num_mn = 400)
{
cout"棋盘已满,平局!"endl;
exit(0);
}
else
{
qipan[y-1][x-1] = 'o';
num_xy;
}
}
void five::getpointmn()
{
cout"请分别输入第"num_mn 1"步黑棋('x')的横坐标和纵坐标:";
cinmn;
if(m = 0 || n = 0 || m20 || n20 )
{
cout"出界,请重新输入:"endl ;
getpointmn();
}
else if(qipan[n-1][m-1]!='.')
{
cout"请所下的位置已经有棋子,请重新输入:" endl;
getpointmn();
}
else if(num_xy num_mn = 400)
{
cout"棋盘已满 , 平局!"endl;
exit(0);
}
else
{
qipan[n-1][m-1] = 'x';
num_mn;
}
}
int five::dangerlevel(int a, int b)
{
int level = 0;
for(int i = 1 ; a i=19; i)
{
if(qipan[a i][b] == '.'ai = 19)
{
i = i 1;
break;
}
if(qipan[ai][b] == 'x'ai = 19)
break;
}
level= (i-1);
for(i = 1 ; a-i=0; i)
{
if(qipan[a-i][b] == '.'(a-i) = 0)
{
i = i 1;
break;
}
if(qipan[a-i][b] == 'x'(a-i) = 0)
break;
}
level= (i-1);
for(i = 1 ; b i=19 ; i)
{
if(qipan[a][bi] == '.'bi = 19)
{
i = i 1;
break;
}
if(qipan[a][bi] == 'x'bi = 19)
break;
}
level= (i-1);
for( i = 1 ; b-i=0 ; i)
{
if(qipan[a][b - i] == '.'(b-i) = 0)
{
i = i 1;
break;
}
if(qipan[a][b - i] == 'x'(b-i) = 0)
break;
}
for( i = 1 ; a i=19 b i=19; i)
{
if(qipan[ai][bi] == '.'b i = 19a i = 19)
{
i = i 1;
break;
}
if(qipan[ai][bi] == 'x'b i = 19a i = 19)
break;
}
level= (i-1);
for( i = 1 ; a-i= 0b-i = 0; i)
{
if(qipan[a - i][b - i] == '.'a-i= 0b-i = 0)
{
i = i 1;
break;
}
if(qipan[a - i][b - i] == 'x'a-i= 0b-i = 0)
break;
}
level= (i-1);
for( i = 1 ; a-i= 0b i = 19 ; i)
{
if(qipan[a - i][bi] == '.'a-i= 0b i = 19)
{
i = i 1;
break;
}
if(qipan[a - i][bi] == 'x'a-i= 0b i = 19)
break;
}
level= (i-1);
for( i = 1 ; ai= 19b-i = 0 ; i)
{
if(qipan[ai][b - i] == '.'ai= 19b-i = 0)
{
i = i 1;
break;
}
if(qipan[ai][b - i] == 'x'ai= 19b-i = 0)
break;
}
level= (i-1);
return level;
}
void five::attack()
{
int num1=1,num2=1,num3=1,num4=1;
int A = 20 , B = 20 ,max = 0;
for(int a = 0 ; a19 ; a)
{
for(int b = 0 ; b19 ; b)
{
if(qipan[a][b] == '.')
{
int level = 0;
for(int i = 1 ; a i=19; i)
{
if(qipan[a i][b] == '.'ai = 19)
{
i = i 1;
break;
}
if(qipan[ai][b] == 'o'ai = 19)
break;
}
level= (i-1);
for(i = 1 ; a-i=0; i)
{
if(qipan[a-i][b] == '.'(a-i) = 0)
{
i = i 1;
break;
}
if(qipan[a-i][b] == 'o'(a-i) = 0)
break;
}
level= (i-1);
for(i = 1 ; b i=19 ; i)
{
if(qipan[a][bi] == '.'bi = 19)
{
i = i 1;
break;
}
if(qipan[a][bi] == 'o'bi = 19)
break;
}
level= (i-1);
for( i = 1 ; b-i=0 ; i)
{
if(qipan[a][b - i] == '.'(b-i) = 0)
{
i = i 1;
break;
}
if(qipan[a][b - i] == 'o'(b-i) = 0)
break;
}
for( i = 1 ; a i=19 b i=19; i)
{
if(qipan[ai][bi] == '.'b i = 19a i = 19)
{
i = i 1;
break;
}
if(qipan[ai][bi] == 'o'b i = 19a i = 19)
break;
}
level= (i-1);
for( i = 1 ; a-i= 0b-i = 0; i)
{
if(qipan[a - i][b - i] == '.'a-i= 0b-i = 0)
{
i = i 1;
break;
}
if(qipan[a - i][b - i] == 'o'a-i= 0b-i = 0)
break;
}
level= (i-1);
for( i = 1 ; a-i= 0b i = 19 ; i)
{
if(qipan[a - i][bi] == '.'a-i= 0b i = 19)
{
i = i 1;
break;
}
if(qipan[a - i][bi] == 'o'a-i= 0b i = 19)
break;
}
level= (i-1);
for( i = 1 ; ai= 19b-i = 0 ; i)
{
if(qipan[ai][b - i] == '.'ai= 19b-i = 0)
{
i = i 1;
break;
}
if(qipan[ai][b - i] == 'o'ai= 19b-i = 0)
break;
}
level= (i-1);
if(level = max)
{
n = a1;
m = b1;
max = level;
}
}
else
continue;
}
}
qipan[n-1][m-1] = 'x';
}
void five::machinemn()
{
int Num1=1,Num2=1,Num3=1,Num4=1,A11 = 21,A12 = 21,A21 = 21,A22 = 21,A31 = 21,A32 = 21,A41 = 21,A42 = 21;
for(int i = x ; ix 5 x 520 ; i)
{
if(qipan[y-1][i] == '.')
{
A11=i;
break;
}
if(qipan[y-1][i] == 'x')
break;
if(qipan[y-1][i] == 'o')
Num1;
}
for(i = x-2; i = 0 ; i --)
{
if(qipan[y-1][i] == '.')
{
A12 = i;
break;
}
if(qipan[y-1][i] == 'x')
{
break;
}
if(qipan[y-1][i] == 'o')
Num1;
}
////
for( i = y ; iy 5y 520 ; i)
{
if(qipan[i][x-1] == '.')
{
A21 = i;
break;
}
if(qipan[i][x-1] == 'x')
{
break;
}
if(qipan[i][x-1] == 'o')
Num2;
}
for(i = y-2; i = 0 ; i --)
{
if(qipan[i][x-1] == '.')
{
A22 = i;
break;
}
if(qipan[i][x-1] == 'x')
{
break;
}
if(qipan[i][x-1] == 'o')
Num2;
}
////
for(i = 0 ; i5x i20y i20; i)
{
if(qipan[y i][x i] == '.')
{
A31 = i;
break;
}
if(qipan[y i][x i] == 'x')
{
break;
}
if(qipan[y i][x i] =='o')
Num3;
}
for(i = 0 ; x - i -2=0y-i-2=0i5;i)
{
if(qipan[y-i-2][x-i-2] == '.')
{
A32 = i;
break;
}
if(qipan[y-i-2][x-i-2] == 'x')
break;
if(qipan[y-i-2][x-i-2] == 'o')
Num3;
}
////
for(i = 0 ; xi20y - i - 2 = 0i5;i)
{
if(qipan[y-i-2][x i] == '.')
{
A41 = i;
break;
}
if(qipan[y-i-2][x i] == 'x')
{
break;
}
if(qipan[y-i-2][x i] == 'o')
Num4;
}
for(i = 0 ; yi20x - i - 2 = 0i5;i)
{
if(qipan[y i][x-i-2] == '.')
{
A42 = i;
break;
}
if(qipan[y i][x-i-2] == 'x')
{
break;
}
if(qipan[y i][x-i-2] == 'o')
Num4;
}
////
if(num_xy == 0num_xy == 0)
{
m = n = 10;
qipan[m-1][n-1] = 'x';
}
else if(num_xy == 1)
attack();
else if(num_xy == 1)
{
m = x 1;
n = x 1;
qipan[m-1][n-1] = 'x';
}
else if(Num1 == 4A11 == 21A12 != 21)//一排四个右边一头堵住
{
n =1y-1;
m = 1A12;
qipan[y-1][A12] = 'x';
}
else if(Num1 == 4A12 == 21A11 != 21)//一排四个左边边一头堵住
{
n =1y-1;
m = 1A11;
qipan[y-1][A11] = 'x';
}
else if(Num2 == 4A21 == 21A22 != 21)//一列四个下边一头堵住
{
n =1A22;
m = 1x-1;
qipan[A22][x-1] = 'x';
}
else if(Num2 == 4A22 == 21A21 != 21)//一列四个上边一头堵住
{
n =1A21;
m = 1x-1;
qipan[A21][x-1] = 'x';
}
else if(Num3 == 4A31 == 21A32 != 21)//一左上右下斜列四个右边一头堵住
{
n =1y - A32 - 2;
m = 1x - A32 - 2;
qipan[y-A32-2][x-A32-2] = 'x';
}
else if(Num3 == 4A32 == 21A31 != 21)//一左上右下斜列四个左边一头堵住
{
n =1yA31;
m = 1xA31;
qipan[y A31][x A31] = 'x';
}
else if(Num4 == 4A41 == 21A42 != 21)//一左下右上斜列四个右边一头堵住
{
n =1yA42;
m = 1x - A42 - 2;
qipan[y A42][x-A42-2] = 'x';
}
else if(Num4 == 4A42 == 21A41 != 21)//一左下右上斜列四个左边一头堵住
{
n =1y - A41 - 2;
m = 1xA41;
qipan[y-A41-2][x A41] = 'x';
}
else if(Num1==3A11 != 21A12 != 21) //一排3 个两头没堵
{
n =1y-1;
m = 1A11;
if(dangerlevel(y-1,A11) = dangerlevel(y-1,A12))
qipan[y-1][A11] = 'x';
else
qipan[y-1][A12] = 'x';
}
else if(Num2==3 A21 != 21A22 != 21) //一列 3 个两头没堵
{
n =1A21;
m = 1x-1;
if(dangerlevel(A21,x-1) = dangerlevel(A22,x-1))
qipan[A21][x-1] = 'x';
else
qipan[A22][x-1] = 'x';
}
else if(Num3 == 3 A31 != 21A32 != 21) //一左上右下斜列3 个两头没堵
{
n =1yA31;
m = 1xA31;
if(dangerlevel(y A31,x A31) = dangerlevel(y-A32 - 2,y - A32 -2))
qipan[y A31][x A31] = 'x';
else
qipan[y-A32-2][x-A32 -2] = 'x';
}
else if(Num4==3A41 != 21A42 != 21) //一左下右上斜列3 个两头没堵
{
n =1y - A41 - 2;
m = 1xA41;
if(dangerlevel(y-A41-2,x A41) = dangerlevel(y-A42-2,x A42))
qipan[y-A41-2][x A41] = 'x';
else
qipan[y-A42-2][x A42] = 'x';
}
else if(Num1 == 2 A11 != 21A12 != 21) //一排2个两头没堵
{
n =1y-1;
m = 1A11;
qipan[y-1][A11] = 'x';
}
else if( Num2 == 2 A21 != 21A22 != 21) //一列2个两头没堵
{
n =1A21;
m = 1x-1;
qipan[A21][x-1] = 'x';
}
else if(Num3 == 2 A31 != 21A32 != 21) //一左上右下斜列2 个两头没堵
{
n =1yA31;
m = 1xA31;
qipan[y A31][x A31] = 'x';
}
else if(Num4==2A41 != 21A42 != 21) //一左下右上斜列2个两头没堵
{
n =1y - A41 - 2;
m = 1xA41;
qipan[y-A41-2][x A41] = 'x';
}
else
attack();
}
void five::showqipan()
{
int p=0,q=0;
for(int i = 0 ; i = 20 ; i)
{
if(p10)
{
coutp ' ';
}
else
coutp ;
p;
}
coutendl;
for(i = 0 ; i20 ; i)
{
if(i=0)
{
q;
if(q10)
coutq ' ';
else
coutq;
}
for(int j = 0 ; j20 ; j)
coutqipan[i][j]' ' ;
coutendl;
}
}
void five::print()
{
int p=0,q=0;
for(int i = 0 ; i = 20 ; i)
{
if(p10)
{
coutp ' ';
}
else
coutp ;
p;
}
coutendl;
for(i = 0 ; i20 ; i)
{
if(i=0)
{
q;
if(q10)
coutq ' ';
else
coutq;
}
for(int j = 0 ; j20 ; j)
{
coutqipan[i][j]' ' ;
}
coutendl;
}
}
bool five::IsxyWin()
{
int num1=1,num2=1,num3=1,num4=1;
for(int i = x ; ix 5 x 520 ; i)
{
if(qipan[y-1][i] != 'o')
break;
if(qipan[y-1][i] == 'o')
num1;
}
for(i = x-2; i = 0 ; i --)
{
if(qipan[y-1][i] != 'o')
break;
if(qipan[y-1][i] == 'o')
num1;
}
for( i = y ; iy 5 ; i)
{
if(qipan[i][x-1] != 'o')
break;
if(qipan[i][x-1] == 'o')
num2;
}
for(i = y-2; i = 0 ; i --)
{
if(qipan[i][x-1] != 'o')
break;
if(qipan[i][x-1] == 'o')
num2;
}
for(i = 0 ; i5x i20y i20; i)
{
if(qipan[y i][x i] != 'o')
break;
if(qipan[y i][x i] =='o')
num3;
}
for(i = 0 ; x - i -2=0y-i-2=0i5;i)
{
if(qipan[y-i-2][x-i-2] != 'o')
break;
if(qipan[y-i-2][x-i-2] == 'o')
num3;
}
for(i = 0 ; xi20y - i - 2 = 0i5;i)
{
if(qipan[y-i-2][x i] != 'o')
break;
if(qipan[y-i-2][x i] == 'o')
num4;
}
for(i = 0 ; yi20x - i - 2 = 0i5;i)
{
if(qipan[y i][x-i-2] != 'o')
break;
if(qipan[y i][x-i-2] == 'o')
num4;
}
if(num1=5||num2=5||num3=5||num4=5)
return 1;
else
return 0;
}
bool five::IsmnWin()
{
int num1=1,num2=1,num3=1,num4=1;
for(int i = m ; im 5 m 520 ; i)
{
if(qipan[n-1][i] != 'x')
break;
if(qipan[n-1][i] == 'x')
num1;
}
for(i = m-2; i = 0 ; i --)
{
if(qipan[n-1][i] != 'x')
break;
if(qipan[n-1][i] == 'x')
num1;
}
for( i = n ; in 5 ; i)
{
if(qipan[i][m-1] != 'x')
break;
if(qipan[i][m-1] == 'x')
num2;
}
for(i = n-2; i = 0 ; i --)
{
if(qipan[i][m-1] != 'x')
break;
if(qipan[i][m-1] == 'x')
num2;
}
for(i = 0 ; i5m i20n i20; i)
{
if(qipan[n i][m i] != 'x')
break;
if(qipan[n i][m i] =='x')
num3;
}
for(i = 0 ; m - i -2=0n-i-2=0i5;i)
{
if(qipan[n-i-2][m-i-2] != 'x')
break;
if(qipan[n-i-2][m-i-2] == 'x')
num3;
}
for(i = 0 ; mi20n - i - 2 = 0i5;i)
{
if(qipan[n-i-2][m i] != 'x')
break;
if(qipan[n-i-2][m i] == 'x')
num4;
}
for(i = 0 ; ni20m - i - 2 = 0i5;i)
{
if(qipan[n i][m-i-2] != 'x')
break;
if(qipan[n i][m-i-2] == 'x')
num4;
}
if(num1=5||num2=5||num3=5||num4=5)
return 1;
else
return 0;
}
void main()
{
five a;
int temp;
cout"欢迎体验本游戏!这是本游戏的棋盘:"endl;
a.showqipan();
cout"双人游戏请按1,人机游戏请按2,退出请按3:";
cintemp;
if(temp == 3)
exit(1);
if(temp == 1)
{
cout"您选择了双人游戏,下面游戏开始:"endl;
for(int i = 0 ; ; i)
{
a.getpointxy();
a.print();
if(a.IsxyWin())
{
cout"白棋胜!"endl;
break;
}
a.getpointmn();
a.print();
if(a.IsmnWin())
{
cout"黑棋胜!"endl;
break;
}
}
}
if(temp == 2)
{
int temp1=0;
cout"您选择了人机游戏 , 您是白棋('o') , 电脑是黑棋('x'),下面游戏开始:"endl;
cout"您先下请按1 , 电脑先下请按2:";
cintemp1;
if(temp1 == 1)
{
for(int i = 0 ; ; i)
{
a.getpointxy();
a.print();
if(a.IsxyWin())
{
cout"你赢了!恭喜!"endl;
break;
}
a.machinemn();
a.print();
cout"电脑走("a.getm()','a.getn()')'endl;
if(a.IsmnWin())
{
cout"哈哈,你输了!"endl;
break;
}
}
}
if(temp1 == 2)
{
for(int i = 0 ; ; i)
{
a.machinemn();
a.print();
if(a.IsmnWin())
{
cout"哈哈,你输了!"endl;
break;
}
a.getpointxy();
a.print();
if(a.IsxyWin())
{
cout"你赢了!恭喜!"endl;
break;
}
}
}
}
cout"Press any key to EXIT\n";
getch();
}
能帮我做一个50行的C语言程序设计作业吗?能运行就行一个转换进制小程序,正好50多行
#includestdio.h
#includestdlib.h
main()
{
void tentotwo(void);
void tentoeight(void);
void tentosixteen(void);
int i,num;
while(1)
{
printf("0.退出 1.十进制~二进制 2.十进制~八进制 3.十进制~十六进制\n");
printf("请选择功能:");
scanf("%d",i);
switch(i)
{
case 0 : return;
case 1 : tentotwo(); break;
case 2 : tentoeight(); break;
case 3 : tentosixteen(); break;
default : printf("you insert a wrong number.\n"); break;
}
}
}
void tentotwo(void)
{
int n;
char buf[32];
printf("请输入一个十进制整数:");
scanf("%d",n);
itoa(n, buf, 2);
printf("转换为二进制:%s\n",buf);
}
void tentoeight(void)
{
int n;
char buf[32];
printf("请输入一个十进制整数:");
scanf("%d",n);
itoa(n, buf, 8);
printf("转换为八进制:%s\n",buf);
}
void tentosixteen(void)
{
int n;
char buf[32];
printf("请输入一个十进制整数:");
scanf("%d",n);
itoa(n, buf, 16);
printf("转换为十六进制:%s\n",buf);
}
关于c语言函数程序设计50行和c语言函数编写程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读